0

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.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Vladimir Gazbarov
  • 860
  • 1
  • 10
  • 25

1 Answers1

1

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)

enhzflep
  • 12,927
  • 2
  • 32
  • 51