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

Use C++ with Nordic SDK (nRF52 series)

Hi, i wrote a lot of firmwares for nRF51x22 using C language and they works fine. Now we passed to nRF52 series and we want to use C++ (preferibly C++11) that is more readable, ordered etc... but i got a lot of difficulties to setup a project.

I'm basing on ble_app_template and i used

extern "C" { }

for all inclusions but i got a lot of errors in some drivers and libraries of SDK.

Can you give me a detailed step-by-step tutorial to setup a project to compile with C++?

I'm using Keil 5.23 with ARMCC 5.06

Thank you.

Parents
  • Here is a example on ble_app_template SDK v13 with minimal alteration.

    ble_app_template_cpp.rar

    and you need to edit components/libraries/experimental_section_vars/nrf_section.h:143

    from

    static section_var __attribute__ ((section("."STRINGIFY(section_name)))) __attribute__((used))

    to

    static section_var __attribute__ ((section( "." STRINGIFY(section_name)))) __attribute__((used))

  • I am trying to use #include <string> and when i use std::string i get undefined reference to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(char const*) const'. Then i was searching for a workaround and found CFLAGS += -D_GLIBCXX_USE_CXX11_ABI=0 which resulted in undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'. I think that this has to do with SDK compiler version. Did somebody solved that?

Reply
  • I am trying to use #include <string> and when i use std::string i get undefined reference to 'std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::compare(char const*) const'. Then i was searching for a workaround and found CFLAGS += -D_GLIBCXX_USE_CXX11_ABI=0 which resulted in undefined reference to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'. I think that this has to do with SDK compiler version. Did somebody solved that?

Children
No Data
Related