【发布时间】:2016-12-16 16:33:40
【问题描述】:
当想要使用 g++ 静态链接所有可用的库时, 此人将 -static 标志传递给编译器。
但是如何从 Qt Creator 中做到这一点?
首先,我尝试了以下建议: How to make Qt and Qtcreator link the libraries statically instead of dynamic?
帖子建议使用
CONFIG += static
但这根本行不通。
其次,我尝试了另一种方法,并将以下行添加到我的 .pro 文件中:
QMAKE_CXXFLAGS += -static
这也没有解决问题。 我分析了编译器输出并发现:
-static 标志仅在将源编译为目标文件时添加。 但是在构建可执行文件时,这个标志是不存在的。
以下是我从编译器输出选项卡复制的确切编译器命令:
g++ -c -pipe -fno-keep-inline-dllexport -static -g -std=gnu++11 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -I..\..\..\ASSETS\PROG_CPP\MY_CPP\2016\test -I. -I..\..\..\icu\dist\include -I..\..\5.7\mingw53_32\mkspecs\win32-g++ -o debug\main.o ..\..\..\ASSETS\PROG_CPP\MY_CPP\2016\test\main.cpp
g++ -Wl,-subsystem,console -mthreads -o debug\test.exe debug/main.o -LC:\icu\dist\lib -lsicuio -lsicuin -lsiculx -lsicule -lsicuuc C:\icu\dist\lib\sicudt.a -lpthread -lm
如何强制Qmake在所有命令中添加-static?
【问题讨论】:
标签: c++ qt-creator static-libraries qmake static-linking