I'm writing a c++ program that is dependent on a c/c++ 3rd-party library. I compiled the 3rd-party library as a static library both on windows and linux. My code works correctly on linux, but on windows there's linking error indicating that my code fails to resolve the symbols in the 3rd-party library.

After some debugging, I found that the unresolved references are non-inline functions in that library and inline functions can be resolved (I've tested). Originally I thought it's the incompatibility between gcc and msvc, because I compiled the .lib files using msvc while attempted to compile my code with g++ through mingw. I recompiled the library with g++ on windows and there's the same problem.

Any idea what might be the solution?

=========Edit===============

Just to clarify, the 3rd-party library is not templated.

有帮助吗?

解决方案

I found the problem: I put both the lib*.a (generated on linux) and .lib (generated on windows) of the 3rd-party library in the same directory, because I want this code to be cross-platform. While compiling my code in windows with g++, it seems link to the lib.a files in priority which leads to "unresolved symbols" error. I deleted the lib*.a files and g++ now link to the *.lib file, and works correctly.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top