Search code examples
c++windowslinkerg++static-linking

g++ - Cant link to static library built with VS2012


I built a static library (.lib) with VS2012. I wrote a test program by including my header and then tried to link it with the .lib file with g++

g++ Test.cpp Gray.lib -o test.exe

(All files are in the same directory)

And I'm getting undefined reference to errors on functions in my library. What do I do? I already searched for many answers, those didn't help.


Solution

  • You cannot do that without resorting to hacks, because name mangling is different between compilers you want to use. The most straigforward way is to complile your library for g++ natively.