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

How to add C++ file to nRF9160 project in SES

Hi,

I'm not sure if SES support C++ compiler in nRF9160 project, I did add C++ source in CMakeList:

   target_sources(app PRIVATE src/xxx.cpp)

It won't work, Does anyone know?

Thanks,

Bertie

Parents
  • Hi.

    Did you enable C++ support using CONFIG_CPLUSPLUS and CONFIG_LIB_CPLUSPLUS?

    Have you tried building from the command line (you will have to set two environment variables first: ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb and GNUARMEMB_TOOLCHAIN_PATH=<path to your toolchain install directory>)?

    While C++ should be supported in NCS, I do not believe it is much tested, so you are largely on your own.

    Best regards,

    Didrik

  • Thanks Didrik,

    I added CONFIG_CPLUSPLUS=y and CONFIG_LIB_CPLUSPLUS=y in prj.conf

    built it on Window SES. Project can be built but just not compile the .cpp file which is in CMakeLists.

    what I tested is to use "hello world" in zephyr\samples\hello_world:

        changed src/main.c to src/main.cpp, also in CMakeLists

        added CONFIG_CPLUSPLUS=y and CONFIG_LIB_CPLUSPLUS=y in prj.conf

        Loaded project into SES, and the main.cpp is not in Project 'app/libapp.a' list, but main.c was there before modification:

        

    build and run on nRF9160 DK board won't print "hello world" on terminal as main.c build does.

    Did I miss something?

    Thanks

Reply
  • Thanks Didrik,

    I added CONFIG_CPLUSPLUS=y and CONFIG_LIB_CPLUSPLUS=y in prj.conf

    built it on Window SES. Project can be built but just not compile the .cpp file which is in CMakeLists.

    what I tested is to use "hello world" in zephyr\samples\hello_world:

        changed src/main.c to src/main.cpp, also in CMakeLists

        added CONFIG_CPLUSPLUS=y and CONFIG_LIB_CPLUSPLUS=y in prj.conf

        Loaded project into SES, and the main.cpp is not in Project 'app/libapp.a' list, but main.c was there before modification:

        

    build and run on nRF9160 DK board won't print "hello world" on terminal as main.c build does.

    Did I miss something?

    Thanks

Children
Related