<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>C++ compilation error using CLI with SDK 14: error: expected declaration before &amp;#39;}&amp;#39; token</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/24745/c-compilation-error-using-cli-with-sdk-14-error-expected-declaration-before-token</link><description>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 &amp;#39;}&amp;#39; token
 }
 ^
 
 What should be the right way to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 04 Mar 2019 10:27:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/24745/c-compilation-error-using-cli-with-sdk-14-error-expected-declaration-before-token" /><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/173924?ContentTypeID=1</link><pubDate>Mon, 04 Mar 2019 10:27:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:49de0393-42f5-46c5-962d-c12d5e4ca8b8</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;Problem fixed. Answer in this thread.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/173900?ContentTypeID=1</link><pubDate>Mon, 04 Mar 2019 09:45:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce237a78-7141-49bc-8879-aae3cf0fdb62</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Please find attached a solution, this should be available in the next SDK release.&lt;/p&gt;
&lt;p&gt;The main difference is in macro resposible for creating subcommands . When using C++ compiler subcommands shall be created with macro:&amp;nbsp;NRF_CLI_CPP_CREATE_STATIC_SUBCMD_SET.&lt;/p&gt;
&lt;p&gt;C++ syntax looks following:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// C++ and C syntax

NRF_CLI_CPP_CREATE_STATIC_SUBCMD_SET(m_sub_print,                                                                       
    NRF_CLI_CMD(all,   NULL, &amp;quot;Print all entered parameters.&amp;quot;, cmd_print_all),                                           
    NRF_CLI_CMD(param, NULL, &amp;quot;Print each parameter in new line.&amp;quot;, cmd_print_param),                                     
    NRF_CLI_SUBCMD_SET_END                                                                                        
);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;While old C syntax was:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/* C only syntax */
NRF_CLI_CREATE_STATIC_SUBCMD_SET(m_sub_print)                                                                            
{                                                                                                                        
    NRF_CLI_CMD(all,   NULL, &amp;quot;Print all entered parameters.&amp;quot;, cmd_print_all),                                            
    NRF_CLI_CMD(param, NULL, &amp;quot;Print each parameter in new line.&amp;quot;, cmd_print_param),                                      
    NRF_CLI_SUBCMD_SET_END                                                                                               
};  &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Please find attached new nrf_cli.h and C++ file with example commands.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/cli.zip"&gt;devzone.nordicsemi.com/.../cli.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;nrf_cli.h can be compiled either by C or C++ compiler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/167266?ContentTypeID=1</link><pubDate>Wed, 23 Jan 2019 06:59:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1353311e-4473-4256-a50f-92eba0239ef5</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;No,&lt;/p&gt;
&lt;p&gt;All files including nrf_cli.h must be compiled with C compiler.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/167262?ContentTypeID=1</link><pubDate>Wed, 23 Jan 2019 06:33:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:29bc7343-5886-40e3-89e2-6e2a532d215e</guid><dc:creator>wtan</dc:creator><description>&lt;p&gt;I&amp;#39;m encountering this issue myself also. Do you have a solution for this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97465?ContentTypeID=1</link><pubDate>Mon, 04 Sep 2017 08:31:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:99a11254-4993-4315-b21e-1d0c0affe9ad</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;Good to read that :).&lt;/p&gt;
&lt;p&gt;Please only keep in mind when using CLI from SDK13.1 that nrf_cli_fprintf will not work correctly for very long strings (exceeding NRF_CLI_PRINTF_BUFF_SIZE) . In such case you will need to split the message.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97464?ContentTypeID=1</link><pubDate>Mon, 04 Sep 2017 08:22:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b474f354-f629-40f3-99d4-dca2bcc3c978</guid><dc:creator>schef</dc:creator><description>&lt;p&gt;On my surprise using cli from SDK13.1 works out of the box. Until then i&amp;#39;m happy with this solution.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97466?ContentTypeID=1</link><pubDate>Fri, 01 Sep 2017 08:39:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd3db5cb-149d-4cf7-8cb1-29b7b3675e02</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Unfortunatelly I am not able to prepare any quick solution for macros which would work. The only recommendation I have for now is to have to add extra file which will wrap C++ class functions to C.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97469?ContentTypeID=1</link><pubDate>Wed, 30 Aug 2017 11:25:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2bf0c714-705e-4161-969d-80d6c49b07ae</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;I am currently working on C++ version of these macros. I will let you know once I will finish (and if I will be able to do it ;) ). Command declaration will be a bit different but you will &lt;strong&gt;not&lt;/strong&gt; need so much manual work.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97467?ContentTypeID=1</link><pubDate>Wed, 30 Aug 2017 10:12:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:51704873-617a-4838-9fc5-170482e6b9b9</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;You don&amp;#39;t need so many files.&lt;/p&gt;
&lt;p&gt;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 &amp;quot;translate&amp;quot; them to C form (unpack from class).&lt;/p&gt;
&lt;p&gt;Next you can include cmd_api.h to C file where you will be adding commands with CLI macros.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97459?ContentTypeID=1</link><pubDate>Wed, 30 Aug 2017 10:04:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dce27be0-30ec-4e86-b16a-0239d1ed5f90</guid><dc:creator>schef</dc:creator><description>&lt;p&gt;Would it be possible to use CLI from the SDK13,1? This module worked.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97468?ContentTypeID=1</link><pubDate>Wed, 30 Aug 2017 09:52:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:38f2955a-c60c-4930-9f2a-1ab85c7ebeed</guid><dc:creator>schef</dc:creator><description>&lt;p&gt;I use Classes. So i would have to write a C implementation for every function i would want to call. I will make some testing and response what works for me.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97460?ContentTypeID=1</link><pubDate>Wed, 30 Aug 2017 08:41:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe8d5908-aed3-4346-ac95-d8deda77da25</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;It is not so easy. For sure you will be not able to use macro: NRF_CLI_CREATE_STATIC_SUBCMD_SET inside C++ file. there is const variable declaration and next its initialization what is not allowed in C++.&lt;/p&gt;
&lt;p&gt;Is it a kind of big problem to implement commands in C file?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97463?ContentTypeID=1</link><pubDate>Wed, 30 Aug 2017 08:37:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:929b5dd7-e052-48db-8445-52a079632600</guid><dc:creator>schef</dc:creator><description>&lt;p&gt;Ok. But that still doesnt help me to call c++ commands directly. Maybe just to make the init in the C file and then registring the commands and subcommands in the c++ file.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97462?ContentTypeID=1</link><pubDate>Wed, 30 Aug 2017 08:05:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9225651d-c565-45c2-a7a2-71854dcdc81a</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;Yes.&lt;/p&gt;
&lt;p&gt;In main.cpp I am only using these 3 functions (handling CLI):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;extern &amp;quot;C&amp;quot; {
extern void cli_start(void);
extern void cli_init(void);
extern void cli_process(void);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&amp;#39;ve created file cli.c where I moved all CLI related stuff. Inside cli.c I have implemented above functions. Now main.cpp is compiled with g++ and cli.c with gcc.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97461?ContentTypeID=1</link><pubDate>Wed, 30 Aug 2017 07:52:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64236af9-be27-433d-b6e4-5bc41d4fe787</guid><dc:creator>schef</dc:creator><description>&lt;p&gt;What do you mean by working fine? Was is usable?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97453?ContentTypeID=1</link><pubDate>Tue, 29 Aug 2017 12:36:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7d89278-79c7-4bce-9ab6-30d35fe99175</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;One more possible solution came to my mind. I will test it during the week. All CLI related functions/macros shall be in C file. I will remove them from main and add one more c file to the example.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97455?ContentTypeID=1</link><pubDate>Tue, 29 Aug 2017 12:03:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3f4d9f89-a368-4780-860d-c67f5d2348cb</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;I can&amp;#39;t find a solution to compile CLI under C++ compiler.
Maybe a workaround would be to add CLI as precompiled library to c++ project.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97454?ContentTypeID=1</link><pubDate>Tue, 29 Aug 2017 10:01:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1d5cc07-42c6-4303-a314-29f3a5a3093e</guid><dc:creator>schef</dc:creator><description>&lt;p&gt;Yes i saw alot of macros inside.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97458?ContentTypeID=1</link><pubDate>Tue, 29 Aug 2017 09:28:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2f6d157-f0fa-46de-9ef7-73a5c8f4ec4c</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;I found a bug causing this error:
In file: nrf_log_backend_interface.h  (sdk\nrf5\components\libraries\experimental_log)&lt;/p&gt;
&lt;p&gt;you need to change last lines from:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#endif // SUPPRESS_INLINE_IMPLEMENTATION

#endif //NRF_LOG_BACKEND_INTERFACE_H

#ifdef __cplusplus
}
#endif
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;to:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#endif // SUPPRESS_INLINE_IMPLEMENTATION

#ifdef __cplusplus
}
#endif

#endif //NRF_LOG_BACKEND_INTERFACE_H
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Unfortunatelly C++ compiler will not manage to handle nrf_cli.h macros.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97457?ContentTypeID=1</link><pubDate>Tue, 29 Aug 2017 08:30:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6746dc16-31e4-4cfc-be5e-241e5bae0cfd</guid><dc:creator>schef</dc:creator><description>&lt;p&gt;&lt;code&gt;examples/peripheral/cli&lt;/code&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ compilation error using CLI with SDK 14: error: expected declaration before '}' token</title><link>https://devzone.nordicsemi.com/thread/97456?ContentTypeID=1</link><pubDate>Tue, 29 Aug 2017 08:29:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d308499c-cb09-4bbc-83e6-42e74aee7bb0</guid><dc:creator>Jakub Rzeszutko</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Please let me know which example you are trying to compile?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>