This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

C++ Compilation Segger Embedded Studio Extern C

Greetings, 

I am relatively new to compilers and I would like some clarification on compiling C++ projects on Segger Embedded Studio with Nordic's SDK vs. 14.2.

I am use to programming in Arduino and I prefer object oriented programming in C++ compared to C and want to make custom c++ libraries for some I2C and SPI devices with the SDK.

I am working with the template project found in the peripheral folder of the SDK with SES. I changed the "main.c" to "main.cpp" to allow it to be compiled by a cpp compiler (C++11 compiler in SES rather than the default gnu++98) and compiles without any warning or errors. 

Question: How do I properly link the .c files found in the SDK with my project? Do I need to include the "__cplusplus" flag to my preprocessor?

I was given the impression that in order to properly link c and c++ files, the "extern "C" " as shown in the snippet below is important and is normally not active at the start of a project. How does this piece code affect the overall compiler and output files? 

#ifdef __cplusplus
extern "C" {
#endif

Thanks in advance!

Parents Reply Children
Related