Build static Qt project with Visual Studio 2015

2019-09-11 22:09发布

问题:

I did the following procedure with the necessary changes according to the Visual Studio version (Community 2015) in order to get a static Qt build.

I configured the QT5Package plugin according to my installation and edited the library/includes path but I'm still unable to build my project.

Here's the output

Qt5Cored.lib(qglobal.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in moc_helloqt.obj
<...>
link warning lnk4098 defaultlib 'libcmtd' conflicts with use of other libs
moc_helloqt.obj : error LNK2001: extern symbol not found "public: static struct QMetaObject const QMainWindow::staticMetaObject" (?staticMetaObject@QMainWindow@@2UQMetaObject@@B)
<...>

回答1:

Problem solved by changing the runtime (MDd->MTd) and including the following libs to the project :

opengl32.lib
Qt5PlatformSupportd.lib
qwindowsd.lib
qtharfbuzzngd.lib
qtpcred.lib
qtfreetyped.lib

These are the libs for the debug build, the libs for the release build are :

opengl32.lib
Qt5PlatformSupport.lib
qwindows.lib
qtharfbuzzng.lib
qtpcre.lib
qtfreetype.lib