Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Problem with compiling C++ code for nRF52820

Hi,

I tried to build the ble_app_uart example for nRF52820/s140. In my project I need to use C++ modules.

My usual approach that worked so far:

  • Take an example project
  • Rename the main.c to main.cpp
  • Replace line 381-385
    ble_gap_phys_t const phys =
    {
        .tx_phys = BLE_GAP_PHY_AUTO,
        .rx_phys = BLE_GAP_PHY_AUTO,
    };
  • Compile with -std=gnu+11.

Oddly this doesn't work with the nRF52820 example and I always get the following error when compiling.

In file included from ../nrf5_sdk/modules/nrfx/mdk/nrf.h:192,
                 from D:\Development\wDALI2_BT_Switch\wdali-2-bt-button\firmware\ble_app_uart_pca10100e_s140\main.cpp:55:
../nrf5_sdk/modules/nrfx/mdk/compiler_abstraction.h:193:60: error: expected constructor, destructor, or type conversion before '(' token
../nrf5_sdk/modules/nrfx/mdk/compiler_abstraction.h:232:5: note: in expansion of macro 'NRF_STATIC_ASSERT'
../nrf5_sdk/modules/nrfx/mdk/nrf_erratas.h:48:1: note: in expansion of macro 'NRF_MDK_VERSION_ASSERT_AT_LEAST'

When I do the same thing with the ble_app_uart example for nRF52840/s140 it compiles just fine with C++.

Does anyone have an idea how to fix this problem and why it only occurs when compiling for nRF52820?

Thanks in advance.

Parents Reply
  • I fixed the problem by replacing lines 192-198 with this code:

    #ifndef NRF_STATIC_ASSERT
        #ifdef __cplusplus
        #define NRF_STATIC_ASSERT(cond, msg) extern char (*_do_assert(void)) [sizeof(char[1 - 2*!(cond)])]
        #else
        #define NRF_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg)
        #endif
    #endif

    Something similar is done in app_util.h of nRF5 SDK 17.0.2.

    Thanks Edvin for your help!

Children
No Data
Related