/ Low Level

Using C++ in PROS

There are currently a few issues with using C++ in PROS.

First thing you might notice is an error like a missing bits/os_defines.h this is because the standard arm-none-eabi-g++ toolkit does not contain many standard C++ headers and libraries, to fix this we have to install newlib:

On debian and ubuntu:
sudo apt-get install libstdc++-arm-none-eabi-newlib
For other linux distributions check your package list, its probably there.

If you are running Windows/OSX you will most likely have to manually install the headers, here is the file structure for newlib:
(gcc 5.4.1) https://packages.debian.org/sid/all/libstdc++-arm-none-eabi-newlib/filelist
(gcc 4.8) https://packages.debian.org/jessie/all/libstdc++-arm-none-eabi-newlib/filelist

Once you have newlib properly installed (and the include directory matches the gcc version you are using) you should have access to a ton more C++ features like tuples.

You will notice that newlib actually conflicts with the PROS API in main.h to fix this I replaced all instances of FILEin the pros headers with PROS_FILE


Another sneaky issue is that the PROS kernel does not call __libc_init_array as its probably not present when the project does not contain C++ code

This means that no static constructors will be called, causing some really frustrating bugs. The solution is to manually call it:

extern "C" {
  void __libc_init_array();
}

void initializeIO() {
  __libc_init_array();
}
Using C++ in PROS
Share this