Page 1 of 1

linker problems

Posted: Mon Apr 14, 2008 4:54 pm
by suthers
I use cygwin as a compiler, nasm as an assembler and ld as a linker.
I can easily jump to a c function from the assembler code, but i cannot go the other way round, the linker always gives an undefined referene error.
I have put a leading underscore in my asm code and i have defined my asm function as extern in my c code (and yes i have checked i haven't missed copied my functions name), but i still get a linker error.
There are no other assembler, compiler or linking errors.
Any ideas what the problem might be?
Thanks in advance,
Jules

Posted: Tue Apr 15, 2008 12:33 am
by xyzzy
I would recommend building an ELF cross-compiler. In my experience Cygwin's compiler has many odd quirks. Basically, I think the problem is that it prepends all symbol names with a _, so when you have an extern for an ASM function, it will put a _ on it. You could try building your code with -fno-leading-underscore, though

Posted: Sat Apr 19, 2008 3:39 am
by thepowersgang
Have you defined the function in the assembler file as global. In C all functions and variables are defined as global by default but in assembler you must explicitly state it as global.

Nasm:

Code: Select all

global _c_function_to_call