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

C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token

Hi, i just renamed main.c to main.cpp.

In file included from ../../../main.cpp:57:0:
../../../../../../components/libraries/experimental_cli/nrf_cli.h:597:1: error: expected declaration before '}' token
 }
 ^

What should be the right way to fix that?

If i put all the include to extern "C" i get:

Compiling file: main.cpp
../../../main.cpp:81:1: error: expected declaration before '}' token
 }
 ^

Thanks.

Parents
  • I found a bug causing this error: In file: nrf_log_backend_interface.h (sdk\nrf5\components\libraries\experimental_log)

    you need to change last lines from:

    #endif // SUPPRESS_INLINE_IMPLEMENTATION
    
    #endif //NRF_LOG_BACKEND_INTERFACE_H
    
    #ifdef __cplusplus
    }
    #endif
    

    to:

    #endif // SUPPRESS_INLINE_IMPLEMENTATION
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif //NRF_LOG_BACKEND_INTERFACE_H
    

    Unfortunatelly C++ compiler will not manage to handle nrf_cli.h macros.

    However I was able to compile this example when I removed all CLI related code to newly added file. I moved there all CLI includes, commands and initialization procedures. It only provided API functions to init, start and process CLI. It was working fine.

Reply
  • I found a bug causing this error: In file: nrf_log_backend_interface.h (sdk\nrf5\components\libraries\experimental_log)

    you need to change last lines from:

    #endif // SUPPRESS_INLINE_IMPLEMENTATION
    
    #endif //NRF_LOG_BACKEND_INTERFACE_H
    
    #ifdef __cplusplus
    }
    #endif
    

    to:

    #endif // SUPPRESS_INLINE_IMPLEMENTATION
    
    #ifdef __cplusplus
    }
    #endif
    
    #endif //NRF_LOG_BACKEND_INTERFACE_H
    

    Unfortunatelly C++ compiler will not manage to handle nrf_cli.h macros.

    However I was able to compile this example when I removed all CLI related code to newly added file. I moved there all CLI includes, commands and initialization procedures. It only provided API functions to init, start and process CLI. It was working fine.

Children
Related