Compile C++ code on CWLITE XMEGA


I am trying to compile a c++ code CWLITE XMEGA, and whenever I start I get this error. The platform & Hal type are not defined. Can you please advise?
…/./hal/hal.h:94:7: warning: “HAL_TYPE” is not defined, evaluates to 0 [-Wundef]
94 | #elif HAL_TYPE == HAL_xmega
| ^~~~~~~~
In file included from FastInf.cpp:4:
…/./hal/hal.h:163:5: warning: “PLATFORM” is not defined, evaluates to 0 [-Wundef]
163 | #if PLATFORM == CW308_MEGARF

If you’re using our build and HAL infrastructure, then you need to define PLATFORM (look at any make command in our Jupyter tutorials for reference).
The supported platforms are defined in hal/Makefile.hal.

I did define the PLATFORM in cell 1 and in the make command just like all the other tutorials, but it still gave the same errors.

adding these lines in the make files made the compilation work, but is there any other way to make it work without manually adding these definitions? Also, whenever I add the trigger setup to get the trigger count, I get these linking errors. Can you please advise?

It’s hard for me to debug changes you’ve made on your own modified codebase. Somehow you must be missing our defines in your modified build process. Trace back where/why that happens, using our unmodified build process as a reference. Your linking error is likely tied to this as well.

I copied a working c tutorial into a new folder and changed the file name to cpp, so v no modifications to the build process occured. However, I still got the same error.

AFAIK, we don’t use any C++ code in any of our projects, so that part of the build system has received little testing. I’d recommend wrapping any header files you include in extern C {} and compiling with make ... VERBOSE=TRUE to see the full build command.


This is what I get using verbose=True

Adding on that when I tried to add manually platform definitions in make file, I got this linking error. When I used extern C, the problem still presists.

Alex can you please check the following and kindly advise because I am using this board for my graduation project

Looking into the makefiles more, adding support for C++ will be kind of tricky. As I said earlier, we don’t use C++ in any of our projects, so I’m not sure when this issue popped up, or if C++ ever worked.

I’ll try adding C++ support, but I’m not sure when this will be finished. In the meantime, I recommend trying to convert C++ files you have into C.


Alright, I’ve got something that seems to mostly work on the latest commit. To build C++ files, you’ll need to:

  1. Go to hal/your_platform and modify the makefile inside to define the appropriate CXX compiler. For example, for the F3, I went to hal/stm32f3/Makefile.stm32f3 and added CXX=arm-none-eabi-g++. Usually this will be the C compiler with g++ replacing gcc
  2. In your C++ file, any C headers you #include will need to be wrapped in extern "C" {}. See simpleserial-aes/simpleserial-aes.cpp for an example of this.
  3. In the makefile for your project, add any C++ source files as CPPSRC += my_cpp_source.cpp. See simpleserial-aes/makefile for a commented out example of this

Some notes:

  • CPPFLAGS is just CFLAGS, so there’s no way to do different CPP and C flags
  • The linker used is based on whether or not CPPSRC is empty, so it should use $(CXX) for linking when there’s at least one file in CPPSRC and $(CC) otherwise

Thank you so so much Alex for your support, it worked on the STM32F3.
However when I try to use it on the atxmega I get this error. Can you please support

You need to use avrg++, not g++

Thanks a lot, it worked with CXX= avr-g++