Hello,
I am using nordic sdk and working with C files.
But i would like to work on with C++ files as well.
How will i modify the makefile so that it can build both C and C++ can you show me an example ? Thanks
Hello,
I am using nordic sdk and working with C files.
But i would like to work on with C++ files as well.
How will i modify the makefile so that it can build both C and C++ can you show me an example ? Thanks
Hi,
Here is a makefile that is made for the ble_app_template example for PCA10028:
You also have to add #extern "C" {}
around everything that talks to the C-domain from cpp. Main.c have to be changed to main.cpp. Here is the ble_app_template project with the ledwrapper Torbjørn made:
thanks it works fine now :)
@olba , what is the diffrence if i use arm-none-eabi-g++ instead ?
None that I know of.
There is little reason to use two different "compilers". Difficulties usually arise when you are linking a library's object file or archive that was compiled with C linkage (for which you don't have the source) linking with source compiled using C++ linkage. The C++ compiler can compile C code (C code is valid C++). Read about "linkage" conventions and "name mangling." In many projects in embedded development, you have all the source code and compile everything (you don't link in a pre-compiled library's object file) so it can all be compiled using C++ linkage.
You don't need to name C++ files with .cpp, that is a convention but the C++ compiler will gladly compile a file with the .c suffix, even if it contains class definitions.
There are other considerations such as calling a method of a dynamic object (on the heap) from a "C" function. See Nordic notes about "wrapping" such methods. But for most simple applications, you can use static objects (usually just one object instance, and not stored on the heap) i.e. class methods and data members. While you could implement such objects in C, using C++ classes might be more understandable.
Another consideration: since much of the SDK is non-strict C++, you might need to add the compiler flag -fpermissive so that you get warnings instead of errors.