Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change qmake release flags for gcc? (Change -O2 to -Os)

Tags:

With qmake you can quite easy change so you build a debug version, or a release version. Just modify the CONFIG var and the compile flags change.

CONFIG += debug
CONFIG += release

When you use the debug you get -g and no optimization, and when you use release you get -O2 and no debug info (no -g).

But where is that specified?

Let's say that I would like my application to be build with optimization for size, -Os? How do I change what is behind "release"?

Thanks

like image 481
Johan Avatar asked Apr 19 '11 11:04

Johan


People also ask

What is qmake command?

qmake is a utility that automates the generation of makefiles. Makefiles are used by the program make to build executable programs from source code; therefore qmake is a make-makefile tool, or makemake for short.

Where is qmake in qt5?

The qmake executable is installed in /usr/lib/<your_arch>/qt5/bin as qmake (no -qt5 suffix).

What is qmake file?

QMake is a build system that generates Makefiles for GNU Make or project build files for Microsoft Visual Studio. It is part of the Qt software framework by Trolltech. While it is commonly used to construct Qt-based software, any project can benefit from it.


2 Answers

You can change global compiler flags by modifying QMAKE_CXXFLAGS. Compiler flags for debug and release builds can be set in QMAKE_CXXFLAGS_DEBUG and QMAKE_CXXFLAGS_RELEASE respectively.

For your concrete example, you should do something like this:

QMAKE_CXXFLAGS_RELEASE -= -O2
QMAKE_CXXFLAGS_RELEASE += -Os
like image 172
mtvec Avatar answered Sep 26 '22 09:09

mtvec


In my case I tried everything I found everywhere and none worked. The only way for me was to hardcode flags inside qt5 installation directory! So just for record, I added these two lines:

QMAKE_CFLAGS_RELEASE = "-march=native -O3 -msse -msse2 -msse3 -mssse3 -fomit-frame-pointer -pipe"
QMAKE_CXXFLAGS_RELEASE = "-march=native -O3 -msse -msse2 -msse3 -mssse3 -fomit-frame-pointer -pipe"

To file:

/opt/qt5/mkspecs/linux-g++/qmake.conf

Please note that I had qt5 compiled and installed on my system in /opt/qt5 path. So you may search a folder named mkspecs in your system then a subfolder named linux-g++ and then a file named qmake.conf to add those two magic lines to it. It's up to you and the envirtonment you are in.

like image 43
Aario Avatar answered Sep 22 '22 09:09

Aario