<?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>replacing main.c with main.cpp</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/80525/replacing-main-c-with-main-cpp</link><description>Hello, 
 
 I am starting to work on a sample project, wherein I need to replace the existing &amp;quot;main.c&amp;quot; file I have with &amp;quot;main.cpp&amp;quot;, by copying the contents of &amp;quot;main.c&amp;quot; into &amp;quot;main.cpp&amp;quot;. Can you please list me the steps I will be required to do to achieve</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 14 Oct 2021 10:13:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/80525/replacing-main-c-with-main-cpp" /><item><title>RE: replacing main.c with main.cpp</title><link>https://devzone.nordicsemi.com/thread/334094?ContentTypeID=1</link><pubDate>Thu, 14 Oct 2021 10:13:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f150e4b9-c0ca-478a-9b5a-d19b9f9383b1</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I just tried to import the project I sent you in Segger, and&amp;nbsp;it built without any problems.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You shouldn&amp;#39;t use the extern &amp;quot;C&amp;quot; keyword around the include statements, like shown in the screenshot. The extern &amp;quot;C&amp;quot; keyword should only be used in the header files themselves, and all the standard Zephyr include files already have this statement.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you look at my example you will see that I only use this statement in the app_bluetooth.h file.&amp;nbsp;&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><item><title>RE: replacing main.c with main.cpp</title><link>https://devzone.nordicsemi.com/thread/333824?ContentTypeID=1</link><pubDate>Wed, 13 Oct 2021 06:05:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:728f1e78-b73d-41a0-b648-cfb65f4e1a9a</guid><dc:creator>Ubaid_M</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/ovrebekk"&gt;ovrebekk&lt;/a&gt;,&lt;br /&gt;&lt;br /&gt;Thanks for the suggestion, I am actually dependent on segger for my development, and the course of evaluation, I found the following issue:&lt;br /&gt;&lt;br /&gt;1. I started with a simple hello_world sample nCS app on segger embedded studio.&lt;/p&gt;
&lt;p&gt;2. Configured and enabled&amp;nbsp;&lt;span&gt;CONFIG_CPLUSPLUS=y&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;3.&amp;nbsp;Replaced main.c into main.cpp by copying contents of main.c into main.cpp&lt;br /&gt;&lt;br /&gt;4. Modified the CMakeLists.txt to include main.cpp as in:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(hello_world)
#src/main.c
target_sources(app PRIVATE D:/CPP_Test/cpp_files/main.cpp)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;5. And ended up with this error in main.cpp:&lt;br /&gt;&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/pastedimage1634034103787v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Kindly suggest and request your help for a way out of this on segger.&lt;br /&gt;&lt;br /&gt;Have attached the project For your reference&lt;/p&gt;
&lt;p&gt;.&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/CPP_5F00_Test.7z"&gt;devzone.nordicsemi.com/.../CPP_5F00_Test.7z&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: replacing main.c with main.cpp</title><link>https://devzone.nordicsemi.com/thread/333775?ContentTypeID=1</link><pubDate>Tue, 12 Oct 2021 14:53:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa405dd2-f690-4e85-ad29-2b5d4e29f368</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I recently made a small example for another customer (regarding &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/80231/c-support-issue-in-nrf-connect-sdk-issue"&gt;this case&lt;/a&gt;), showing how to use C++ in an nRF Connect SDK Bluetooth sample.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In order to include .cpp files in your build all you have to do is make sure .cpp files are included in the CMakeLists.txt file, as I did with this line:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;FILE(GLOB app_sources src/*.c src/*.cpp)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;With that change in place it should be sufficient just to rename your main.c file to main.cpp.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The full example (for v1.6.1) is here:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/3683.277456_5F00_peripheral_5F00_hr_5F00_cpp.zip"&gt;devzone.nordicsemi.com/.../3683.277456_5F00_peripheral_5F00_hr_5F00_cpp.zip&lt;/a&gt;&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><item><title>RE: replacing main.c with main.cpp</title><link>https://devzone.nordicsemi.com/thread/333613?ContentTypeID=1</link><pubDate>Tue, 12 Oct 2021 04:44:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:068bbcbd-4cbd-4d5f-a840-4fbb640c4096</guid><dc:creator>Ubaid_M</dc:creator><description>&lt;p&gt;Coupled this query with a relative query in&lt;/p&gt;
&lt;p&gt;&lt;a title="main.c into main.cpp" href="https://devzone.nordicsemi.com/f/nordic-q-a/80528/defining-the-path-for-multiple-files"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/80528/defining-the-path-for-multiple-files&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>