Qmake: how to remove compiler flag for a certain project, without changing qmake.conf?

一笑奈何 提交于 2019-11-26 17:14:01

问题


I'm using qmake and Visual Studio. In release build qmake adds /GL and /O2 flags to all projects, and I need to remove those two flags for certain libraries within my whole Qt project. Is there a way?


回答1:


The only way this could work is

QMAKE_CFLAGS -= /GL /O2

but I doubt this works for QMAKE_CFLAGS.

Alternatively, you could redefine QMAKE_CFLAGS, forgetting its previous value:

QMAKE_CFLAGS = $$CFLAGS_WITHOUT_GL_O2



回答2:


I had a similar problem and I solved it by adding the following directive in the .pro file:

QMAKE_CXXFLAGS_RELEASE -= -g

Observe the _RELEASE suffix, otherwise don't work.




回答3:


I edited my .pro file by using this, and it worked!

QMAKE_CXXFLAGS_RELEASE  -= -Zc:strictStrings
QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO -= -Zc:strictStrings

It does not work:

QMAKE_CFLAGS_RELEASE -= -Zc:strictStrings
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO -= -Zc:strictStrings

You can try:

QMAKE_CXXFLAGS_RELEASE  -= -GL -O2
QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO -= -GL -O2

Take a look in:

your Qt dir\compiler\mkspecs\win32-msvc2013\qmake.conf




回答4:


You can edit the qmakespec which is used by your configuration.

The easiest way to find it is by opening

%QTDIR%\mkspecs\%QMAKESPEC%

assuming the environment variables are set (they should be)

Just in case it's not working, it will be something like C:\Qt\4.x.x\mkspecs\win32-msvc2010

In the qmake.conf file you can adjust the folling two lines (they are in different places in the file)

QMAKE_CFLAGS_RELEASE    = -O2 -MT
QMAKE_CFLAGS_LTCG       = -GL

to

QMAKE_CFLAGS_RELEASE    = -MT
QMAKE_CFLAGS_LTCG       =

However note that you will have to do this for every Qt Version you are using (and for every future update you will do).

[Edit]
If you want to have -O2 -GL options for certain projects you will have to add

QMAKE_CFLAGS_RELEASE    += -O2
QMAKE_CFLAGS_LTCG       += -GL

to the .pro file of the projects which need those options.

Dependent on the amount of projects which use it and the ones which don't, either this approach or redefining QMAKE_CFLAGS will be more convenient.




回答5:


If -= does not work

try in your .pro file

QMAKE_CFLAGS = $$replace(QMAKE_CFLAGS, "-GL ", "")
QMAKE_CFLAGS = $$replace(QMAKE_CFLAGS, "-O2 ", "")



回答6:


Recently I faced the same problem. I had to remove the Zc:strictStrings compiler flag. I've learned immediately that just removing does not work. So, the solution is to override the flag by including this string into .pro file

QMAKE_CXXFLAGS+=-Zc:strictStrings-

Like this the compiler prints a warning: cl : Command line warning D9025 : overriding '/Zc:strictStrings' with '/Zc:strictStrings-' but still it does the job.



来源:https://stackoverflow.com/questions/8241567/qmake-how-to-remove-compiler-flag-for-a-certain-project-without-changing-qmake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!