C++ 如何在PlatformIO中启用错误抛出?(我得到了g+;+;错误。)

C++ 如何在PlatformIO中启用错误抛出?(我得到了g+;+;错误。),c++,arduino,g++,platformio,C++,Arduino,G++,Platformio,我试图在我的Arduino以太网代码中抛出错误(if(error)throw error)并处理(really ignore:catch(error error){})它们。遗憾的是,我遇到了如下错误: src\main.cpp: In function 'void loop()': src\main.cpp:29:35: error: exception handling disabled, use -fexceptions to enable } catch (Error erro

我试图在我的Arduino以太网代码中抛出错误(
if(error)throw error
)并处理(really ignore:
catch(error error){}
)它们。遗憾的是,我遇到了如下错误:

src\main.cpp: In function 'void loop()':
src\main.cpp:29:35: error: exception handling disabled, use -fexceptions to enable
     } catch (Error error) {
                    ^
我了解到我需要将以下内容添加到我的
platformio.ini
文件中以启用错误处理:

build_flags = -fexceptions
build_unflags = -fno-exceptions
现在,在编译过程中,我得到以下信息:

<artificial>:(.text+0xaf8): undefined reference to `__cxa_allocate_exception'
<artificial>:(.text+0xb0a): undefined reference to `__cxa_throw'
...
<artificial>:(.text.startup+0x5c): undefined reference to `__gxx_personality_sj0'
<artificial>:(.text.startup+0x5e): undefined reference to `__gxx_personality_sj0'
<artificial>:(.text.startup+0x116): undefined reference to `setup'
<artificial>:(.text.startup+0x1fa): undefined reference to `__cxa_begin_catch'
<artificial>:(.text.startup+0x1fe): undefined reference to `__cxa_end_catch'
:(.text+0xaf8):对“cxa\u分配\u异常”的未定义引用
:(.text+0xb0a):对“\uuucxa\uthrow”的未定义引用
...
:(.text.startup+0x5c):未定义对“\uuugxx\u personality\u sj0”的引用
:(.text.startup+0x5e):未定义对“\uuugxx\u personality\u sj0”的引用
:(.text.startup+0x116):未定义对“setup”的引用
:(.text.startup+0x1fa):对“cxa\u begin\u catch”的未定义引用
:(.text.startup+0x1fe):未定义对“cxa\u end\u catch”的引用

我该怎么办?

我想是AVR架构(AVR-g++)。如中所示,它不受支持:

不支持异常。由于异常在C++前端中被默认启用,因此它们需要使用编译器选项中的-FNO异常来关闭。否则,链接器将抱怨对uugxx_personality_sj0的未定义外部引用

这是因为普通C++前端,并且因为默认情况下启用了异常。


但是,例如在STM32duino(STM32 Arm MCU)中,可以使用-fexceptions(以及STL和更多)

请将编译器命令行/makefile添加到问题中。你连接了C++运行库吗?例外情况可能是76k闪存更有趣。你每天都能学到新东西!谢谢