vs2010静态链接Qt

先按照这个帖子弄好静态库

http://www.cnblogs.com/rollenholt/articles/2518642.html 

注意原文中config那一步最后一个"-"输入成了中文状态下的"—",正确的如下:

configure -debug-and-release -fast -static -platform win32-msvc2010 -no-qt3support -script -scripttools -qt-zlib -qt-libpng -qt-libmng -qt-libtiff -qt-libjpeg -qt-sql-sqlite -plugin-sql-sqlite -qt-style-windows -qt-style-windowsxp -qt-style-windowsvista -qt-style-plastique -qt-style-cleanlooks -qt-style-motif -qt-style-cde -nomake demos -nomake examples -nomake docs -mp

 

选中VS的Qt菜单中Qt->Qt Options 的Qt Versions标签。点击右边的Add增加

Version name我输入的是4.8.3_static, path就是选中刚才你那个Qt源码的目录

增加完成后就在下面那个ComboBox中选中你刚才加的版本。

对于已经在vs中建好的Qt工程, 右键点击工程->Qt Project Settings

然后在弹出的对话框的Properties标签中的Version选项选择你刚才建立的版本。

最后需要在你的代码中导入这两个库

#pragma comment (lib, "winmm.lib")

#pragma comment (lib, "imm32.lib")

注:我这边只用了Qt的Core library和GUI library,对于引用了Qt其他模块的可能需要导入更多的库

注2:对于Release版的编译,可能会出现在lib库中函数多重定义的错误,需要在项目的

属性-> 链接器 -> 输入 

然后选择右边的忽略特定默认库输入MSVCRT.lib 

看起来就像下面这个样子:

原文地址:https://www.cnblogs.com/Bonker/p/3565040.html