简体   繁体   中英

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

So I have a particle photon embedded board. And I have the local build system set up on a Windows platform, using mingw, per: https://docs.particle.io/faq/particle-tools/local-build/photon/ . Lastly, I would really like to use the statechart library from the boost set of libraries.

Per the boost statechart library configuration page, it should be possible to use it even with RTTI disabled: http://www.boost.org/doc/libs/1_65_1/libs/statechart/doc/configuration.html#GeneralConfiguration (The RTTI is disabled in the build makefile with -fno-rtti. As one might expect.)

So I added the flag -DBOOST_NO_RTTI to the build configuration and confirm that it's present in the compile command.

However upon testing a simple 'blinkled' application where the simplest header files are included:

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

with build command:

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'

results in a list of errors, basically inferring it's not possible to use the library with 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 );

Have I misunderstood something here in regard to potential for usage with RTTI (or exceptions)? I understand the limitations involved, just trying to work out how to build the application.

It would be a shame if not possible, it's a nice library.

Try adding -DNDEBUG to your compilation command.


Boost Statechart 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)

Your error message comes from a BOOST_ASSERT , so I dove into the source code of rtti_policy.hpp to find

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

It seems that the way Statechart is detecting whether you are in debug mode is by inspecting the NDEBUG preprocessor macro.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM