<?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>use c++ for nrf51 in keil</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/21462/use-c-for-nrf51-in-keil</link><description>hello there i want to use c++ library in nrf51dk project. i am using sdk12.
i change main.c to main.cpp
but i am getting error. uart_original.rar 
 i have uploaded code here. In abc.cpp file i declared like 
 #include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 24 Apr 2017 11:07:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/21462/use-c-for-nrf51-in-keil" /><item><title>RE: use c++ for nrf51 in keil</title><link>https://devzone.nordicsemi.com/thread/84216?ContentTypeID=1</link><pubDate>Mon, 24 Apr 2017 11:07:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf7ba2a8-2f79-456b-b826-6d924b43e5f7</guid><dc:creator>nordicbeginner</dc:creator><description>&lt;p&gt;thanks. its working&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: use c++ for nrf51 in keil</title><link>https://devzone.nordicsemi.com/thread/84215?ContentTypeID=1</link><pubDate>Mon, 24 Apr 2017 07:59:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8ce5ad66-bcfc-44c7-8094-0a12579b565b</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;For clarity, are you using SDK v12.0.0, or one of the newer versions?
My response is based on the assumption that you use v12.0.0.&lt;/p&gt;
&lt;p&gt;One issue is that you don&amp;#39;t include function prototypes in abc.h, which means your main file is not able to find those functions.
In other words you have to add the function prototypes like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void uart_init();
int uart_return();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Secondly there appears to be an issue in bsp.h where the C++ include guard is located in the wrong place. To fix this find the following section:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#ifdef BSP_UART_SUPPORT
#include &amp;quot;app_uart.h&amp;quot;

#ifdef __cplusplus
extern &amp;quot;C&amp;quot; {
#endif
#endif // BSP_UART_SUPPORT
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And change it to this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#ifdef BSP_UART_SUPPORT
#include &amp;quot;app_uart.h&amp;quot;

#endif // BSP_UART_SUPPORT

#ifdef __cplusplus
extern &amp;quot;C&amp;quot; {
#endif    
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;By making those changes I was able to get your code to compile.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: use c++ for nrf51 in keil</title><link>https://devzone.nordicsemi.com/thread/84214?ContentTypeID=1</link><pubDate>Thu, 20 Apr 2017 12:03:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e99d41f3-5172-48ed-93b7-2fbf802d3ccb</guid><dc:creator>nordicbeginner</dc:creator><description>&lt;p&gt;i made changes. what you said. but i am getting same error. i have updated code here&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: use c++ for nrf51 in keil</title><link>https://devzone.nordicsemi.com/thread/84213?ContentTypeID=1</link><pubDate>Thu, 20 Apr 2017 11:08:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:760adec4-b9b9-4875-9912-48fb8328f4e1</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;All you have to do to allow C++ in a file is to configure that file as a C++ file (renaming it to .cpp is not strictly necessary):&lt;br /&gt;
&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/cpp_5F00_select.png" alt="image description" /&gt;&lt;/p&gt;
&lt;p&gt;As for your code example, why are you including the .cpp files from main.cpp?
The .h files should be included, and the .cpp files should be added to your code project.&lt;/p&gt;
&lt;p&gt;Looking at the code your issues don&amp;#39;t seem to be C++ related as much as related to linking issues (not including the right files at the right places).&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;
Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>