assembly files linked with c files, djgpp
category: code [glöplog]
I'm having trouble linking my files under djgpp.
main.c:
hello.s:
compile like this:
Now this should compile no problem. It work on unix. When I try and compile the same thing under djgpp I get an undefined reference to hello when linking.
objdump hello.o shows hello in the symbol table. What's up with djgpp?
main.c:
Code:
#include <stdio.h>
extern int hello;
int main(void) {
printf("%d\n", hello);
}
hello.s:
Code:
.section .rodata
.globl hello
.align 4
hello:
.int 23
compile like this:
Code:
gcc main.c hello.s
Now this should compile no problem. It work on unix. When I try and compile the same thing under djgpp I get an undefined reference to hello when linking.
objdump hello.o shows hello in the symbol table. What's up with djgpp?
Nevermind everybody I figured it out
... you're suppose to put a _ before all your symbols
...so nice to see people doing oldschool stuff :) Good for you, sigflup :)
Happy to see the Genesis attack on oldschool PCs! :)
Makes me want to revive my 386 code and start finally coding an oldschool demo too (have been saying this since ages :P). And then everybody ressurects the 286/386/486 scene =)
Makes me want to revive my 386 code and start finally coding an oldschool demo too (have been saying this since ages :P). And then everybody ressurects the 286/386/486 scene =)
Also note you might need to specify extern "C" if you're compiling C++
It will NOT need an underscore if targeting ELF executables (ELF requires external symbols to have the same name). Keep it in mind if you are doing hand-made assembler and will be aiming for ELF files.
there actually was a pc 64k for a 286 laptop running dos 3.8 (or something) at flashback thise weekend :)
Quote:
there actually was a pc 64k for a 286 laptop running dos 3.8 (or something) at flashback thise weekend :)
Wow really? Long Live 286/386/486 scene!
Quote:
there actually was a pc 64k for a 286 laptop running dos 3.8 (or something) at flashback thise weekend :)
Don't bogart the warez! Gimme dl link.
Jcl: sorry, I'm a bit confused - is it possible to run ELF exes on DOS?
elf on dos? weird idea. O_o theoretically you could. write a loader and bit of environment to setup. elf is still just a kinda container for code and data. is it?. :)
With the appropriate DOS Extender, this could work. But, is it of any use ?
bitnaughty: not in any way I know of, however, if you are using djgpp, chances are you are trying to write portable code, and if you write the underscores manually, it won't work when using other compilers. Also, the same would apply to ELF object files, not just executables (which djgpp can use, and he might be using since he's using .rodata sections instead of the older .text sections which were used on COFF object files)
Jcl: thanks
Where is the 286 flashback intro?
well a video capture of it can be found here but there seems to be no binary so ive not added it to pouet db yet.