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

I am using qmake and Visual Studio. In the release release, qmake adds / GL and / O2 flags to all projects, and I need to remove these two flags for specific libraries throughout my Qt project. Is there any way?

+7
source share
6 answers

The only way this could work is

 QMAKE_CFLAGS -= /GL /O2 

but I doubt this works for QMAKE_CFLAGS .

Alternatively, you can override QMAKE_CFLAGS , forgetting about your previous value:

 QMAKE_CFLAGS = $$CFLAGS_WITHOUT_GL_O2 
+3
source

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

QMAKE_CXXFLAGS_RELEASE - = -g

Observe the suffix _RELEASE, otherwise do not work.

+9
source

I edited my .pro file using this and it will work!

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

Does not work:

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

You may try:

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

Take a look at:

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

+5
source

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

The easiest way to find this is to open

 %QTDIR%\mkspecs\%QMAKESPEC% 

Assuming environment variables are set (they should be)

Just in case, it does not work, it will be something like C:\Qt\4.xx\mkspecs\win32-msvc2010

In the qmake.conf file, you can configure the following 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, keep in mind that you will need to do this for each version of Qt used (and for each future update you will do).

[Change]
If you want to have -O2 -GL options for specific projects, you will need to add

 QMAKE_CFLAGS_RELEASE += -O2 QMAKE_CFLAGS_LTCG += -GL 

into the .pro file of projects that need these parameters.

Depending on the number of projects that use it and those that don’t, this approach or overriding QMAKE_CFLAGS will be more convenient.

+1
source

If -= does not work

try in your .pro file

 QMAKE_CFLAGS = $$replace(QMAKE_CFLAGS, "-GL ", "") QMAKE_CFLAGS = $$replace(QMAKE_CFLAGS, "-O2 ", "") 
+1
source

I recently ran into the same problem. I had to remove the Zc: strictStrings compiler flag. I immediately realized that just removing does not work. So the solution is to override the flag by including this line in the .pro file

QMAKE_CXXFLAGS+=-Zc:strictStrings-

Thus, the compiler displays a warning: cl: Command line warning D9025: redefines '/ Zc: strictStrings' to '/ Zc: strictStrings-', but still it does its job.

0
source

Source: https://habr.com/ru/post/902192/


All Articles