Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

gcc

qmake

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.

like image 489
Martin Drozdik Avatar asked Jan 24 '14 14:01

Martin Drozdik


People also ask

What does run qmake do?

The qmake tool helps simplify the build process for development projects across different platforms. It automates the generation of Makefiles so that only a few lines of information are needed to create each Makefile. You can use qmake for any software project, whether it is written with Qt or not.

What is qmake command?

The qmake tool provides you with a project-oriented system for managing the build process for applications, libraries, and other components. This approach gives you control over the source files used, and allows each of the steps in the process to be described concisely, typically within a single file.

What is CMake and qmake?

CMake is an alternative to qmake for automating the generation of build configurations. Setting Up Qbs. Qbs is an all-in-one build tool that generates a build graph from a high-level project description (like qmake or CMake do) and executes the commands in the low-level build graph (like make does).

How use qmake and make?

For simple projects, you only need to run qmake in the top level directory of your project. By default, qmake generates a Makefile that you then use to build the project, and you can then run your platform's make tool to build the project. qmake can also be used to generate project files.


1 Answers

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)

like image 143
matthieu Avatar answered Oct 07 '22 00:10

matthieu