Constexpr compile error

I encounter a compilation error in the uORB code when adding my own module to PX4, but I can’t figure out how I triggered this error.

The problems seems to be that “constexpr” is not recognized, but since I can see the command-line argument “-std=gnu11”, I don’t know why it doesn’t recognize it as an C++11 feature. The compile command generated by the build system seems OK to me:

/usr/lib/ccache/arm-none-eabi-gcc -DCONFIG_ARCH_BOARD_CUBEPILOT_CUBEORANGE -    DMODULE_NAME=\"atmos_safety\" -DPX4_MAIN=atmos_safety_app_main -D_SYS_CDEFS_H_ -D_SYS_REENT_H_ -D__CUSTOM_FILE_IO__ -D__PX4_NUTTX -D__STDC_FORMAT_MACROS -isystem ../../platforms/nuttx/NuttX/include/cxx -isystem NuttX/nuttx/include/cxx -isystem NuttX/nuttx/include -I../../boards/cubepilot/cubeorange/src -I../../platforms/nuttx/src/px4/common/include -I. -Isrc/lib -I../../platforms/nuttx/src/px4/stm/stm32h7/include -I../../platforms/common/include -I../../src -I../../src/include -I../../src/lib -I../../src/lib/matrix -I../../src/modules -INuttX/nuttx/arch/arm/src/armv7-m -INuttX/nuttx/arch/arm/src/chip -INuttX/nuttx/arch/arm/src/common -INuttX/apps/include -Iexternal/Install/include -I../../src/modules/atmos_safety/px4/src/lib/drivers/device -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -Os -DNDEBUG   -g -fdata-sections -ffunction-sections -fomit-frame-pointer -fmerge-all-constants -fno-signed-zeros -fno-trapping-math -freciprocal-math -fno-math-errno -fno-strict-aliasing -fvisibility=hidden -include visibility.h -Wall -Wextra -Werror -Warray-bounds -Wcast-align -Wdisabled-optimization -Wdouble-promotion -Wfatal-errors -Wfloat-equal -Wformat-security -Winit-self -Wlogical-op -Wpointer-arith -Wshadow -Wuninitialized -Wunknown-pragmas -Wunused-variable -Wno-missing-field-initializers -Wno-missing-include-dirs -Wno-unused-parameter -Wno-logical-op -fdiagnostics-color=always -fno-builtin-printf -fno-strength-reduce -Wformat=1 -Wunused-but-set-variable -Wno-format-truncation -fno-common -Wbad-function-cast -Wnested-externs -Wstrict-prototypes -Wframe-larger-than=2048 -std=gnu11 -MD -MT src/modules/atmos_safety/CMakeFiles/modules__atmos_safety.dir/atmos_safety_main.c.obj -MF src/modules/atmos_safety/CMakeFiles/modules__atmos_safety.dir/atmos_safety_main.c.obj.d -o src/modules/atmos_safety/CMakeFiles/modules__atmos_safety.dir/atmos_safety_main.c.obj   -c ../../src/modules/atmos_safety/atmos_safety_main.c
In file included from ../../src/modules/uORB/Subscription.hpp:42:0,
                 from ../../src/modules/atmos_safety/atmos_safety.h:4,
                 from ../../src/modules/atmos_safety/atmos_safety_main.c:1:
./uORB/topics/uORBTopics.hpp:41:8: error: unknown type name 'constexpr'
 static constexpr size_t ORB_TOPICS_COUNT{181};
        ^~~~~~~~~
compilation terminated due to -Wfatal-errors.

Did anyone encounter this before?

Try changing atmos_safety_main.c to atmos_safety_main.cpp.

1 Like

Thanks for pointing this out!