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
  • Hi,

    Please find attached a solution, this should be available in the next SDK release.

    The main difference is in macro resposible for creating subcommands . When using C++ compiler subcommands shall be created with macro: NRF_CLI_CPP_CREATE_STATIC_SUBCMD_SET.

    C++ syntax looks following:

    // C++ and C syntax
    
    NRF_CLI_CPP_CREATE_STATIC_SUBCMD_SET(m_sub_print,                                                                       
        NRF_CLI_CMD(all,   NULL, "Print all entered parameters.", cmd_print_all),                                           
        NRF_CLI_CMD(param, NULL, "Print each parameter in new line.", cmd_print_param),                                     
        NRF_CLI_SUBCMD_SET_END                                                                                        
    );

    While old C syntax was:

    /* C only syntax */
    NRF_CLI_CREATE_STATIC_SUBCMD_SET(m_sub_print)                                                                            
    {                                                                                                                        
        NRF_CLI_CMD(all,   NULL, "Print all entered parameters.", cmd_print_all),                                            
        NRF_CLI_CMD(param, NULL, "Print each parameter in new line.", cmd_print_param),                                      
        NRF_CLI_SUBCMD_SET_END                                                                                               
    };  

    Please find attached new nrf_cli.h and C++ file with example commands.

    cli.zip

    nrf_cli.h can be compiled either by C or C++ compiler.

Reply
  • Hi,

    Please find attached a solution, this should be available in the next SDK release.

    The main difference is in macro resposible for creating subcommands . When using C++ compiler subcommands shall be created with macro: NRF_CLI_CPP_CREATE_STATIC_SUBCMD_SET.

    C++ syntax looks following:

    // C++ and C syntax
    
    NRF_CLI_CPP_CREATE_STATIC_SUBCMD_SET(m_sub_print,                                                                       
        NRF_CLI_CMD(all,   NULL, "Print all entered parameters.", cmd_print_all),                                           
        NRF_CLI_CMD(param, NULL, "Print each parameter in new line.", cmd_print_param),                                     
        NRF_CLI_SUBCMD_SET_END                                                                                        
    );

    While old C syntax was:

    /* C only syntax */
    NRF_CLI_CREATE_STATIC_SUBCMD_SET(m_sub_print)                                                                            
    {                                                                                                                        
        NRF_CLI_CMD(all,   NULL, "Print all entered parameters.", cmd_print_all),                                            
        NRF_CLI_CMD(param, NULL, "Print each parameter in new line.", cmd_print_param),                                      
        NRF_CLI_SUBCMD_SET_END                                                                                               
    };  

    Please find attached new nrf_cli.h and C++ file with example commands.

    cli.zip

    nrf_cli.h can be compiled either by C or C++ compiler.

Children
No Data
Related