How to enable exception handling in mingw

浪尽此生 提交于 2019-12-13 19:45:06

问题


I am new to Mingw and C++ programming. I am trying to build a C++ project but getting following error.

error: exception handling disabled, use -fexceptions to enable.

Where I need to pass this -fexceptions parameter. When I am trying

mingw32-make -fexceptions

I am getting follwoing error.

mingw32-make: exceptions: No such file or directory


回答1:


Since you're using Qt, add "exceptions" to the CONFIG variable in your project file (the *.pro file):

CONFIG += exceptions

This should take care of passing the correct compiler flags.

In any event, do not modify the generated Makefile. With Qt's qmake, the Makefile is just an auto-generated file.




回答2:


If you're using straight g++ from the command line, you should do:

g++ -fexceptions ...rest of command...

If you're using Makefiles, add it to CXXFLAGS (and then just build with make as usual):

# in your Makefile
CXXFLAGS := -fexceptions
...rest of your makefile...

The reason you get the "No such file or directory" error is because -f is an option for make which specifies the file to use, so when you pass -fexceptions to make it says "-f means he wants to use the following file "exceptions"... let me try and find a file named "exceptions"" and then, of course, it errors out when it can't find a file by that name.

The CXXFLAGS variable in your Makefile get passed to your compiler as flags/options, and is where you should stick any extra compiler flags (like -fexceptions).

Edit: If you're using qmake, try adding CONFIG += exceptions to your project file.



来源:https://stackoverflow.com/questions/13401719/how-to-enable-exception-handling-in-mingw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!