This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

C++ compilation error with SDK 12.1.0 and 12.0.0: error: expected declaration before '}' token

Getting the error when trying to compile the C++ project with SDK 12.1.0:

In file included from .../components/softdevice/common/softdevice_handler/softdevice_handler.h:41:0,
                 from main.cpp:11:
.../components/softdevice/common/softdevice_handler/ant_stack_handler_types.h:78:1: error: expected declaration before '}' token
 }
 ^

The same with SDK 12.0.0.

  • Here is the patch:

    diff -rcN nRF5-SDK-12.1.0/components/proprietary_rf/gzll/nrf_gzll_error.h nRF5-SDK-12.1.0-fix/components/proprietary_rf/gzll/nrf_gzll_error.h
    *** nRF5-SDK-12.1.0/components/proprietary_rf/gzll/nrf_gzll_error.h	2016-10-04 14:09:12.000000000 +0300
    --- nRF5-SDK-12.1.0-fix/components/proprietary_rf/gzll/nrf_gzll_error.h	2016-11-03 01:06:19.489624670 +0300
    ***************
    *** 22,27 ****
    --- 22,31 ----
      #include "nrf_gzll.h"
      #include "app_error.h"
      
    + #ifdef __cplusplus
    + extern "C" {
    + #endif
    + 
      #define GAZELLE_ERROR_CODE_CHECK(GZLL_RESULT)                                       \
          do                                                                              \
          {                                                                               \
    diff -rcN nRF5-SDK-12.1.0/components/softdevice/common/softdevice_handler/ant_stack_handler_types.h nRF5-SDK-12.1.0-fix/components/softdevice/common/softdevice_handler/ant_stack_handler_types.h
    *** nRF5-SDK-12.1.0/components/softdevice/common/softdevice_handler/ant_stack_handler_types.h	2016-10-04 14:09:12.000000000 +0300
    --- nRF5-SDK-12.1.0-fix/components/softdevice/common/softdevice_handler/ant_stack_handler_types.h	2016-11-03 01:18:58.564026665 +0300
    ***************
    *** 65,70 ****
    --- 65,74 ----
       */
      uint32_t softdevice_ant_evt_handler_set(ant_evt_handler_t ant_evt_handler);
      
    + #ifdef __cplusplus
    + }
    + #endif
    + 
      #else
      
      // The ANT Stack support is not required.
    ***************
    *** 73,83 ****
      
      #endif // ANT_STACK_SUPPORT_REQD
      
    - 
    - #ifdef __cplusplus
    - }
    - #endif
    - 
      #endif // ANT_STACK_HANDLER_TYPES_H__
      
      /** @} */
    --- 77,82 ----
    
  • As a Nordic employee, I can confirm this bug and have tested the patch.

    There is also a bug in bsp.h. Here is a patch:

    diff -rcN nRF5-SDK-12.1.0/examples/bsp/bsp.h nRF5-SDK-12.1.0/examples/bsp/bsp_fix.h
    *** nRF5-SDK-12.1.0/examples/bsp/bsp.h       Tue Oct  4 14:09:12 2016
    --- nRF5-SDK-12.1.0/examples/bsp/bsp_fix.h   Thu Nov  3 16:03:07 2016
    ***************
    *** 32,37 ****
    --- 32,41 ----
      #include <stdbool.h>
      #include "boards.h"
    
    + #ifdef __cplusplus
    + extern "C" {
    + #endif
    +
      #if !defined(BSP_DEFINES_ONLY) && !defined(BSP_SIMPLE)
      #include "app_button.h"
    
    ***************
    *** 45,54 ****
       */
      #ifdef BSP_UART_SUPPORT
      #include "app_uart.h"
    -
    - #ifdef __cplusplus
    - extern "C" {
    - #endif
      #endif // BSP_UART_SUPPORT
    
      #define BUTTON_ERASE_BONDING BSP_BUTTON_0_MASK
    --- 49,54 ----
    
  • Thank you. I didn't found an official issue tracker or any other way to send a feedback. Is it convenient for you if the bug reports and/or fixes will be posted here?

  • Hi pratoriandroid, Yes. this is convenient as this thread link will be added to known_issues so that everyone can find it.

Related