Quantcast
Viewing all articles
Browse latest Browse all 22145

GCC adding underscore to external symbols from .o file

I'm trying to compile an opengl application into one executable file on windows. Everything worked fine on one machine with mingw which I can't tell its version now, while on another machine the compilation failed at linking stage, which said undefined reference of my external symbols like this:

#ifdef __cplusplusextern "C" {#endif    extern const char _binary_misc_a_obj_start, _binary_misc_a_obj_end;#ifdef __cplusplus}#endif

So I tried nm command, which said:

         U __binary_misc_a_obj_end         U __binary_misc_a_obj_start006ac818 D _binary_misc_a_obj_end006ac818 A _binary_misc_a_obj_size00000000 D _binary_misc_a_obj_start

After I removed the leading underscore of the symbol, it worked. And the output of nm is:

         U _binary_misc_a_obj_end         U _binary_misc_a_obj_start006ac818 D _binary_misc_a_obj_end006ac818 A _binary_misc_a_obj_size00000000 D _binary_misc_a_obj_start

And this output is what I saw on the previous machine where I use the original symbol name: extern const char _binary_misc_a_obj_start, _binary_misc_a_obj_end;, while actually now the code is extern const char binary_misc_a_obj_start, binary_misc_a_obj_end;

Where I am confused is that two versions of gcc act different on the same windows platform. How can I avoid such unpredictalble linking failure.

I can't quite remember the mingw version I was using on the first machine, while the mingw version on this machine is i686-7.2.0-posix-dwarf-rt_v5-rev1. Both machines use win10 as operating system.


Viewing all articles
Browse latest Browse all 22145

Trending Articles