在项目 .pro 文件中我指定了:
QMAKE_CXXFLAGS += -fno-exceptions
但我可以在我的应用程序中抛出异常。对此有什么想法吗?
示例:这不应该起作用,但它起作用
#include <QApplication>
#include <QtDebug>
int main(int c, char**v)
{
QApplication app(c,v);
try
{
throw 1;
}
catch(int i)
{
}
return app.exec();
}
您不能通过设置来关闭异常QMAKE_CXXFLAGS
因为这个选项是由CONFIG
。你应该使用
CONFIG-=exceptions
将它们关闭。
如果两者都没有,请参阅 g++ 参数QMAKE_CXXFLAGS
nor CONFIG
设置更改:
g++ -c -O2 -frtti -fexceptions -mthreads -Wall <...> main.cpp
现在,让我们设置QMAKE_CXXFLAGS
: get
g++ -c -fno-exceptions -O2 -frtti -fexceptions -mthreads -Wall <...> main.cpp
哎呀,我们得到了-fno-exceptions
被覆盖CONFIG
's -fexceptions
。
现在,让我们设置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
哦!编译错误!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)