问题
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