Zephyr RTOS: 启用 C++ 异常

huangapple go评论69阅读模式
英文:

Zephyr RTOS: Enabling C++ Exceptions

问题

I'm trying to enable C++ Exceptions for Zephyr (Version 3.2.99). The documentation only states, that CONFIG_EXCEPTIONS must be enabled.

Where do I have to enable cpp exceptions, so that -fno-exceptions is not passed?

I enabled it in the CMakeLists.txt

cmake_minimum_required(VERSION 3.20.0)
set(BOARD xiao_ble)
find_package(Zephyr)
project(my_project)
# ...
target_sources(app PRIVATE
        src/main.cpp
# ...
        )
target_compile_options(app PRIVATE -fexceptions)

and in the KConfig (prj.conf):

# CPP
CONFIG_CPLUSPLUS=y
CONFIG_EXCEPTIONS=y
# ...

but still a -fno-exceptions is passed when building the project.

英文:

I'm trying to enable C++ Exceptions for Zephyr (Version 3.2.99). The documentation only states, that CONFIG_EXCEPTIONS must be enabled.

Where do I have to enable cpp exceptions, so that -fno-exceptions is not passed?

I enabled it in the CMakeLists.txt

cmake_minimum_required(VERSION 3.20.0)
set(BOARD xiao_ble)
find_package(Zephyr)
project(my_project)
# ...
target_sources(app PRIVATE
        src/main.cpp
# ...
        )
target_compile_options(app PRIVATE -fexceptions)

and in the KConfig (prj.conf):

# CPP
CONFIG_CPLUSPLUS=y
CONFIG_EXCEPTIONS=y
# ...

but still a -fno-exceptions is passed when building the project.

答案1

得分: 0

I didn't read the CMake output properly. The KConfig in the question produces the following warning: warning: EXCEPTIONS (defined at subsys/cpp/Kconfig:76) was assigned the value 'y' but got the value 'n'. Check these unsatisfied dependencies: LIB_CPLUSPLUS (=n).

This is because enabling the CONFIG_EXCEPTIONS requires CONFIG_LIB_CPLUSPLUS to be enabled and CONFIG_NEWLIB_LIBC_NANO to be disabled, as stated in the KConfig options documentation. After adding these two configurations to the prj.conf file like this:

# CPP
CONFIG_CPLUSPLUS=y
CONFIG_NEWLIB_LIBC_NANO=n
CONFIG_LIB_CPLUSPLUS=y
CONFIG_EXCEPTIONS=y
# ... any other configurations

exceptions can be thrown.

英文:

I didn't read the CMake output properly. The KConfig in the question produces the following warning: warning: EXCEPTIONS (defined at subsys/cpp/Kconfig:76) was assigned the value 'y' but got the value
'n'. Check these unsatisfied dependencies: LIB_CPLUSPLUS (=n).

This is because enabling the CONFIG_EXCEPTIONS requires CONFIG_LIB_CPLUSPLUS to be enabled and CONFIG_NEWLIB_LIBC_NANO to be disabled, as stated in the KConfig options documentation. After adding these two configurations to the prj.conf file like this:

# CPP
CONFIG_CPLUSPLUS=y
CONFIG_NEWLIB_LIBC_NANO=n
CONFIG_LIB_CPLUSPLUS=y
CONFIG_EXCEPTIONS=y
# ... any other configurations

exceptions can be thrown.

huangapple
  • 本文由 发表于 2023年5月22日 18:30:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76305274.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定