NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: nobody on January 07, 2008, 02:21:41 PM
-
hello, I am trying to write C functions with nasm and I cannot get gcc to link them.
I wrote this assembly code:
somefunc.asm
somefunc:
ret
And this C code:
main.c
extern void somefunc(void)
int main(void)
{
somefunc();
return 0;
}
and when I compile:
nasm -f elf somefunc.asm
gcc -c main.c
gcc main.o somefunc.o -o test
I get:
main.o: In function `main':
main.c:(.text+0x12): undefined reference to `somefunc'
collect2: ld returned 1 exit status
But objdump tells me that there is a somefunc symbol in my object file:
objdump -d somefunc.o
somefunc.o: file format elf32-i386
Disassembly of section .text:
00000000 :
0: c3 ret
any ideas ?
regards.
-
In your asm file, "global somefunc". For "non-ELF C", you'd probably want an underscore on it.
In general, "global" for stuff that's in this file, and we need to tell ld about it. "extern" for stuff that's *not* in this file (but is referenced)... and we need to tell ld about it.
(BTW, there's a utility named "test", so make sure you use "./test" to get "your test", rather than the utility)
Best,
Frank
-
It works!
thank you for being so fast.
-
I dont Understand Can Post new code?