Reputation: 860
I have the problem where the linker generates undefined reference errors from the inline assembly code.
int global_var = 0;
void myfunc()
{
asm(".intel_syntax noprefix\n");
asm("lea eax, global_var\n");
}
I am compiling with -masm=intel and with no optimizations or anything, using GCC 3.4.2 If anyone suffered from this inconvenience too please assist.
Upvotes: 0
Views: 1874
Reputation: 13109
Basically, it's an issue of name mangling - that is to say, the compiler mangles(alters) the names of variables and functions during the compile phase. In this instance, "global_var" is altered to "_global_var"
If you change the 2nd line of your function such that it accesses "_global_var" then it compiles just fine. (tested GCC 4.7.1)
Upvotes: 1