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.

  • You don't need so many files.

    The easiest solution which come to my mind is that you can create something like: cmd_api.cpp and cmd_api.h. You can collect there all class functions and "translate" them to C form (unpack from class).

    Next you can include cmd_api.h to C file where you will be adding commands with CLI macros.

    In SDK 14 you shall be able to use CLI from SDK13.1 but it will require some effort to migrate it. And you will have all limitations of old console.

Reply
  • You don't need so many files.

    The easiest solution which come to my mind is that you can create something like: cmd_api.cpp and cmd_api.h. You can collect there all class functions and "translate" them to C form (unpack from class).

    Next you can include cmd_api.h to C file where you will be adding commands with CLI macros.

    In SDK 14 you shall be able to use CLI from SDK13.1 but it will require some effort to migrate it. And you will have all limitations of old console.

Children
No Data
Related