Question

I am trying to pass optimization flags to gcc 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 project TestGrounds...
15:14:34: Starting:
"/usr/bin/make" clean rm -f main.o
rm -f *~ core *.core
15:14:34: The process "/usr/bin/make" exited normally.
15:14:34: Configuration unchanged, skipping qmake step.
15:14:34: Starting: "/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" exited normally.
15:14:35: Elapsed time: 00:01.

But why are the -O1 and -O2 optimization flags passed too?

I tried to clean the project and rebuild it and the result is the same.

Was it helpful?

Solution 2

Try this

QMAKE_CXXFLAGS_RELEASE -= -O1
QMAKE_CXXFLAGS_RELEASE -= -O2
QMAKE_CXXFLAGS_RELEASE *= -O3

OTHER TIPS

There an easier option now, add this in the project settings:

CONFIG += optimize_full

Or in your .pro:

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

It will replace the -O2 with -O3. (seems to be there since 2014)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top