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

时间:2017-09-20 20:18:50

标签: c++ boost particle.io particle-photon

所以我有一个粒子光子嵌入板。我在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 (使用-fno-rtti在构建makefile中禁用了RTTI。正如人们所料。)

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

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

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

使用build命令:

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(或例外)的可能性?我理解所涉及的限制,只是试图找出如何构建应用程序。

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

1 个答案:

答案 0 :(得分:1)

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

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

  

调试模式编译选项

     
      
  • 必须打开C ++ RTTI(由各种断言使用)
  •   

您的错误消息来自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预处理器宏。