在MingW x86静态库环境下编译dll动态库
在qmake配置文件mkspecs\win32-g++\qmake.conf文件中,
1.若设置:
QMAKE_LFLAGS=-static
QMAKE_LFLAGS_DLL=-static
则QT Library 工程编译时报错:undefined reference to "WinMain@16",编译失败。
2.若设置:
QMAKE_LFLAGS=
QMAKE_LFLAGS_DLL = -shared
则QT Library工程编译通过,编译结果dll依赖于依赖于libgcc_s_dw2-1.dll,libstdc++-6.dll,libwinpthread-1.dll三者。
3.若设置:
QMAKE_FLAGS=-static
QMAKE_FLAGS_DLL=-shared
则QT Library工程编译通过,生成的dll不依赖于libgcc_s_dw2-1.dll,libstdc++-6.dll,libwinpthread-1.dll三者。
经验证,在情况3下,dll可以发布使用。
从结果分析原因:
qmake.conf配置变量描述:
Specifies a general set of flags that are passed to the linker. If you need to change the flags used for a particular platform or type of project, use one of the specialized variables for that purpose instead of this variable.
修改QMAKE_LFLAG=-static,实际是修改生成shared library(MingW 下为dll)时,采用的链接方式,在QT静态编译环境下(QT SDK只有.a静态库),应该采用-static静态链接才正确。另外一种可行的方法是,不修改原qmake.conf参数配置,在qmake.conf中添加:
QMAKE_LFLAGS_SHLIB = -static也可。