This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Programming nrf51x22 with Keil in C++

Hi All,

I was wondering if it was possible to program the nrf51x22 in c++? I am using Keil and I'm trying to convert the examples in the SDK to CPP by adding --cpp to the compiler string and

#ifdef __cplusplus
extern "C" {
#endif

...

#ifdef __cplusplus
}
#endif

to the headers but I cant seem to compile these targets. Could someone tell me how to configure Keil to use either the ARM or the GCC compiler for this? When switching to GCC I keep getting the error target CPU does not support ARM mode.

Regards,

Alex

  • Does the answer above mean that it is not possible to do C++ development (to be exact, mixing C & C++) on Keil?

  • I don't know about Keil but the startup code for GCC from the SDK does not work with C++. It is missing the initialization for C++ runtime library. All the include from the SDK also missing the extern "C" encapsulation. One of the SVC call function do not compiles in C++. See my blog for change require for that function.

  • Thanks for the explanation. As far as I see, the mbed team has already made the SDK C++ compatible and it is possible to export projects from their online toolchain to Keil or GCC. I have tried that with some online example projects and it seems to work easily. Why do I want to move to C++? Because, many open source libraries are written in C++. So, I would be glad indeed, if Nordic could support the C++ development directly...

  • Thanks, I got it to compile! EDIT: I completely agree with azdem..

  • Hi Everyone,

    I'm trying follow something similar which you guys I have tried. I'm trying to mix C & C++. I get the below build error when I try it with GCC and Eclipse.

    make[1]: *** No rule to make target _build/system_nrf51.o', needed bynrf51422_xxac_s110'. Stop. make: *** [all] Error 2

    As @Nguyen Hoan Hoang has mentioned the SDK also missing the extern "C" encapsulation. One of the SVC call function do not compiles in C++. Should I believe that the is no way I can compile C++ code with the current SDK. To mention I'm using SDK v10 Thanks

Related