Here is an example of the relevant part of my 32 bit code (I use NASM):
Code: Select all
[BITS 32]
extern _somefunction
call _somefunction
cmp eax,0x12345678
jne elsewhere
In a .c file (let's pretend it's second.c) I have written:
Code: Select all
int _somefunction()
{
/*perform some useful function
and return a value.*/
return 0x12345678;
}
nasmw -f coff -o first.o first.asm
gcc -ffreestanding -c -o second.o second.c
ld -Ttext 0x100000 --oformat binary -o result.bin first.o second.o
The problem is that the linker reports:
undefined reference to '_somefunction'
occurring at the appropriate location in the first.asm file.
Do I need to somehow declare that somefunction() should be exported?
I found HOWTO about mixing assembly and C very useful but it does not discuss going the other way i.e. calling C from assembly.
Thanks in advance for your help.