Porting a C++ library


I developed a C++ library that compiles on many platforms (Linux and Windows on PCs, Buildroot Linux on ARM). The only dependency of this library is the standard C++ library. I’m trying to compile it with the native board, to start with. The real target will be ESP32S3 DevKit board, whose compiler does provide libstdc++.

I created a package in my test project directory under pkg/librst.

The compilation outputs a whole lot of errors, the first one being error: unknown type name ‘namespace’. A dry run (make -n) tells me that gcc is called, but I expect g++ to be called. Yet, I did add the cpp and libstdcpp dependencies to FEATURES_REQUIRED.

I’m really stuck, here. Any idea ?

Files in the package


PKG_NAME    = librst
PKG_URL     = https://...
PKG_VERSION = f84e0d...
PKG_LICENSE = proprietary

include $(RIOTBASE)/pkg/pkg.mk

	$(info BINDIR = ${BINDIR})
	$(info BOARD = ${BOARD})
    # copy library's include files to BINDIR :
	mkdir -p $(BINDIR)/$(PKG_NAME)/include
	cp $(PKG_SOURCE_DIR)/*.h $(BINDIR)/$(PKG_NAME)/include
	$(MAKE) -C $(PKG_SOURCE_DIR) -f $(RIOTBASE)/Makefile.base


INCLUDES += -I$(BINDIR)/librst/include
INCLUDES += -I/usr/include/c++/13
INCLUDES += -I/usr/include/x86_64-linux-gnu/c++/13



It seems like I made some progress with that command line :

$ make CC=g++ CFLAGS+=-std=c++11 CFLAGS+=-fpermissive

g++ is now invoked instead of gcc, the coding standard (previously gnu-11) fits a C++ compiler, and some non-C++ casts are allowed.

My C++ library compiles without errors, but the compilation stops with numerous errors like ‘thread_t’ {aka ‘struct _thread’} has no member named <some_member_name> in RIOT/core/msg.c.

Any idea ?

I don’t have a direct answer for you, but perhaps it might be worth looking at the pkg/etl or the pkg/talking_leds packages. talking_leds indirectly uses C++ because it pulls in Arduino support. etl is a C++ library, so it may be very applicable as a starting point for what you are trying to do.

Also, are the names of the files in your C++ package ending in .c or .cpp? I don’t know if RIOT’s build system cares, but convention is often to invoke gcc or g++ depending on the file suffix.

Thanks for your reply. But, I finally ported my library from C++ to C. The C version compiles smoothly.

Besides, I seized the opportunity to adapt the variable types for microcontrollers.