Why does qmake add O1 and -O2 optimization flags in this case?

I am trying to pass gcc optimization flags using the qmake.pro file:

hello.pro:

TEMPLATE = app CONFIG += console CONFIG -= app_bundle CONFIG -= qt SOURCES += main.cpp QMAKE_CXXFLAGS += -O3 \ 

main.cpp:

 #include <iostream> int main() { std::cout << "Hi!" << std::endl; return 0; } 

compilation output:

15:14:34: Running steps for the TestGrounds project ...
15:14:34: Start:
"/ usr / bin / make" clean rm -f main.o
rm -f * ~ core * .core
15:14:34: The process "/ usr / bin / make" went fine.
15:14:34: The configuration has not changed, skipping the qmake step.
15:14:34: Start: "/ usr / bin / make"
g ++ -c -pipe -O3 -O2 -Wall -W -fPIE -I / opt / Qt5.2.0 / 5.2.0 / gcc / mkspecs / linux-g ++ -I ../../ Projects / TestGrounds -I. -o main.o ../../ Projects / TestGrounds / main.cpp
g ++ -Wl, -O1 -Wl, -rpath, / opt / Qt5.2.0 / 5.2.0 / gcc -o TestGrounds main.o
15:14:35: The process "/ usr / bin / make" went fine.
15:14:35: Elapsed time: 00:01.

But why do the optimization flags -O1 and -O2 exist?

I tried to clean the project and rebuild it, and the result will be the same.

+7
c ++ gcc qmake
source share
2 answers

try it

 QMAKE_CXXFLAGS_RELEASE -= -O1 QMAKE_CXXFLAGS_RELEASE -= -O2 QMAKE_CXXFLAGS_RELEASE *= -O3 
+11
source share

Now there is a simpler option, add this to the project settings:

 CONFIG += optimize_full 

Or in your .pro:

 CONFIG(release, debug|release) { CONFIG += optimize_full } 

It will replace -O2 with -O3. (It seems to exist since 2014)

+1
source share

All Articles