Boost Statechart库可以与粒子光子嵌入式系统一起使用吗

Can Boost Statechart library be used with the particle photon embedded system

所以我有一个粒子光子嵌入式板。我在 Windows 平台上设置了本地构建系统,使用 mingw,per: https://docs.particle.io/faq/particle-tools/local-build/photon/。最后,我真的很想使用 boost 库集中的状态图库。

根据 boost 状态图库配置页面,即使禁用 RTTI 也应该可以使用它:http://www.boost.org/doc/libs/1_65_1/libs/statechart/doc/configuration.html#GeneralConfiguration (RTTI 在带有 -fno-rtti 的构建 makefile 中被禁用。正如人们所期望的那样。)

所以我将标志 -DBOOST_NO_RTTI 添加到构建配置并确认它存在于编译命令中。

然而,在测试包含最简单的头文件的简单 'blinkled' 应用程序时:

#include <boost/statechart/state_machine.hpp>
#include <boost/statechart/simple_state.hpp>

使用构建命令:

make -C ../modules/photon/user-part all
make[1]: Entering directory `/d/projects/software/particle/firmware/modules/photon/user-part'
make -C ../../../user 
make[2]: Entering directory `/d/projects/software/particle/firmware/user'
Building cpp file: ../../blinkled//src/blinkled.cpp
Invoking: ARM GCC CPP Compiler
mkdir -p ../build/target/user/platform-6-m/blinkled/src/
arm-none-eabi-gcc -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_ID=6 -DPLATFORM_NAME=photon -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD006 -DUSBD_PID_CDC=0xC006 -DSPARK_PLATFORM -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=6 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=0.6.2 -DRELEASE_BUILD -I./inc -I../wiring/inc -I../system/inc -I../services/inc -I../communication/src -I../hal/inc -I../hal/shared -I../hal/src/photon -I../hal/src/stm32f2xx -I../hal/src/stm32 -I../hal/src/photon/api -I../platform/shared/inc -I../platform/MCU/STM32F2xx/CMSIS/Include -I../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include -I../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_Host_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_OTG_Driver/inc -I../dynalib/inc -I../../blinkled//src -I../../blinkled//inc -I../../blinkled//../boost -I./libraries -I../../blinkled//src -I../../blinkled//src -I../../blinkled//src -I../../blinkled//src -I. -MD -MP -MF ../build/target/user/platform-6-m/blinkled/src/blinkled.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DSPARK_PLATFORM_NET=BCM9WCDUSI09 -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc  -DLOG_INCLUDE_SOURCE_INFO=1 -DPARTICLE_USER_MODULE -DUSE_THREADING=0 -DUSE_THREADING=0 -DUSE_SPI=SPI -DUSE_CS=A2 -DUSE_SPI=SPI -DUSE_CS=A2 -DUSER_FIRMWARE_IMAGE_SIZE=0x20000 -DUSER_FIRMWARE_IMAGE_LOCATION=0x80A0000 -DMODULAR_FIRMWARE=1 -DMODULE_VERSION=4 -DMODULE_FUNCTION=5 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=4,2,108 -D_WINSOCK_H -D_GNU_SOURCE -DLOG_MODULE_CATEGORY="\"app\""  -fno-exceptions -fno-rtti -fcheck-new -DRELEASE -DBOOST_NO_RTTI -std=gnu++11 -c -o ../build/target/user/platform-6-m/blinkled/src/blinkled.o ../../blinkled//src/blinkled.cpp
make[2]: Leaving directory `/d/projects/software/particle/firmware/user'
make[1]: Leaving directory `/d/projects/software/particle/firmware/modules/photon/user-part'

导致错误列表,基本上推断无法将库与 RTTI 一起使用。:

In file included from ../../blinkled//../boost/boost/assert.hpp:58:0,
                 from ../../blinkled//../boost/boost/statechart/detail/rtti_policy.hpp:11,
                 from ../../blinkled//../boost/boost/statechart/event_base.hpp:11,
                 from ../../blinkled//../boost/boost/statechart/event.hpp:11,
                 from ../../blinkled//../boost/boost/statechart/state_machine.hpp:11,
                 from ../../blinkled//src/blinkled.cpp:4:
../../blinkled//../boost/boost/statechart/detail/rtti_policy.hpp: In member function 'const CustomId* boost::statechart::detail::rtti_policy::rtti_base_type<Base>::custom_dynamic_type_ptr() const':
../../blinkled//../boost/boost/statechart/detail/rtti_policy.hpp:106:62: error: cannot use typeid with -fno-rtti
           ( *idProvider_->pCustomIdType_ == typeid( CustomId ) ) );
                                                              ^
../../blinkled//../boost/boost/statechart/detail/rtti_policy.hpp:104:9: note: in expansion of macro 'BOOST_ASSERT'
         BOOST_ASSERT(
         ^
../../blinkled//../boost/boost/statechart/detail/rtti_policy.hpp: In static member function 'static const CustomId* boost::statechart::detail::rtti_policy::rtti_derived_type<MostDerived, Base>::custom_static_type_ptr()':
../../blinkled//../boost/boost/statechart/detail/rtti_policy.hpp:172:30: error: cannot use typeid with -fno-rtti
             typeid( CustomId ) ) );
                              ^
../../blinkled//../boost/boost/statechart/detail/rtti_policy.hpp:169:9: note: in expansion of macro 'BOOST_ASSERT'
         BOOST_ASSERT(
         ^
In file included from ../../blinkled//../boost/boost/statechart/event_base.hpp:11:0,
                 from ../../blinkled//../boost/boost/statechart/event.hpp:11,
                 from ../../blinkled//../boost/boost/statechart/state_machine.hpp:11,
                 from ../../blinkled//src/blinkled.cpp:4:
../../blinkled//../boost/boost/statechart/detail/rtti_policy.hpp: In static member function 'static void boost::statechart::detail::rtti_policy::rtti_derived_type<MostDerived, Base>::custom_static_type_ptr(const CustomId*)':
../../blinkled//../boost/boost/statechart/detail/rtti_policy.hpp:182:29: error: cannot use typeid with -fno-rtti
           &typeid( CustomId );

关于与 RTTI(或例外)一起使用的可能性,我是否误解了这里的某些内容?我了解所涉及的限制,只是想弄清楚如何构建应用程序。

如果不可能,那将是一种耻辱,这是一个不错的图书馆。

尝试将 -DNDEBUG 添加到您的编译命令中。


提升状态图requires RTTI to be enabled when it's compiled in "debug mode":

Debug mode compilation options

  • C++ RTTI must be turned on (used by various asserts)

你的错误信息来自BOOST_ASSERT,所以我深入rtti_policy.hpp的源代码找到

struct id_provider
{
  const void * pCustomId_;
  #if defined( BOOST_ENABLE_ASSERT_HANDLER ) || !defined( NDEBUG )
  const std::type_info * pCustomIdType_;
  #endif
};

Statechart 检测您是否处于调试模式的方式似乎是通过检查 NDEBUG 预处理器宏。