Why is my code compiling with -fno exceptions in Qt Creator when I try to use exceptions?

In the .pro project file, I specified:

QMAKE_CXXFLAGS += -fno-exceptions  

But I can throw exceptions from my application. Any thoughts on this?

Example: this should not work, but it works

#include <QApplication>
#include <QtDebug>

int main(int c, char**v)
{
    QApplication app(c,v);
    try
    {
        throw 1;
    }
    catch(int i)
    {

    }
    return app.exec();
}
+5
source share
3 answers

You do not turn off exceptions by setting QMAKE_CXXFLAGSbecause these parameters are processed CONFIG. You have to use

CONFIG-=exceptions

to disable them.

See g ++ arguments if you have neither settings QMAKE_CXXFLAGSnor CONFIG:

g++ -c -O2 -frtti -fexceptions -mthreads -Wall <...> main.cpp

Now install set QMAKE_CXXFLAGS: get

g++ -c -fno-exceptions -O2 -frtti -fexceptions -mthreads -Wall <...> main.cpp

Oooh, we get our -fno-exceptionsredefined CONFIG -fexceptions. Now let set CONFIG:

g++ -c -O2 -frtti -Wall -fno-exceptions <...> main.cpp
mingw32-make.exe[1]: Leaving directory `G:/proj/ingeritance'
main.cpp: In function 'int qMain(int, char**)':
main.cpp:22:15: error: exception handling disabled, use -fexceptions to enable
mingw32-make.exe[1]: *** [release/main.o] Error 1
mingw32-make.exe: *** [release] Error 2

ABOUT! compilation error!

+11
source

.

( ) , , , -fno-exceptions. , try catch, , , .

. GCC. :

++ .

, , ( ) "", . , , , , .

+6

try using both of the following

QMAKE_CFLAGS_RELEASE -= -fno-exceptions

QMAKE_CXXFLAGS_RELEASE -= -fno-exceptions
+2
source

All Articles