0

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

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

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

然而,在测试一个简单的“闪烁”应用程序时,其中包含了最简单的头文件:

#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(或例外)一起使用的可能性,我在这里是否误解了一些东西?我了解所涉及的限制,只是想弄清楚如何构建应用程序。

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

4

1 回答 1

1

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


Boost Statechart需要在“调试模式”下编译时启用 RTTI

调试模式编译选项

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

您的错误消息来自 a ,因此我深入研究rtti_policy.hppBOOST_ASSERT的源代码以查找

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

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

于 2017-09-20T20:58:01.940 回答