Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake is not enabling exceptions

I have a small C++ program that I need to use exceptions in. When I try to compile it I get the error:

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

In my CMakeLists.txt I set the C++ version to 11 and enable -fexceptions

set(CMAKE_CXX_STANDARD 11)
...
target_compile_options (test PUBLIC -fexceptions)

Edit: for future readers this is for a Raspberry Pi Pico, and I found the answer.

like image 206
Mr.Samson Avatar asked Nov 29 '25 02:11

Mr.Samson


2 Answers

After walking away from the problem for a while and coming back to it I found the answer. This was for a Raspberry Pi Pico; I didn't think that was important, but it turned out to be very important. Following the comment from t.niese I searched the sdk for -fno-exceptions and found in the sdk where exceptions were turned off. After reading the sdk documentation I added the line set(PICO_ENABLE_CXX_EXCEPTIONS 1) to my CMakeLists.txt file and that turned exceptions on.

like image 94
Mr.Samson Avatar answered Nov 30 '25 16:11

Mr.Samson


Like what Mr.Samson suggest, but I use "set(PICO_CXX_ENABLE_EXCEPTIONS 1)".

like image 25
Horizon Avatar answered Nov 30 '25 17:11

Horizon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!