linker problems

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

linker problems

Post 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
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Post 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
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Post 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
Post Reply