PDA

View Full Version : How to add static library of visual C++ to QT project



pipi
27th July 2014, 09:18
Hello everyone, I have a mylib.lib, I use the Visual C++ 2012 compiler (making a Windows).
I want add it to my QT project ( build with minGW). if in debug mode it show "error: LNK1104: cannot open file 'MyLibd.lib'" and release mode it cannot link to method in my lib ( undefined reference to method or error: LNK1257: code generation failed)

- .pro:

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/lib/ -lMyLib
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/lib/ -lMyLibd
else:unix: LIBS += -L$$PWD/lib/ -lMyLib

INCLUDEPATH += $$PWD/lib
DEPENDPATH += $$PWD/lib

Please help me some hint to fix it.

Thanks!

stampede
27th July 2014, 22:29
error: LNK1104: cannot open file 'MyLibd.lib
Static libraries built with different compilers will be incompatible, there is no way to link to a static C++ library compiled with vc++ to code compiled with gcc. This limitation does not affect plain "C" libraries - you can compile a static C library with gcc and use (link to) it in visual studio.
Solution is to add the library sources to your Qt/gcc project and rebuild everything with the same compiler (of course only if you don't use anything specific to vc++ in this library).