CMake/C++ template for frc control development

I’m developing a project template for developing and deploying control code using cmake/c++. I’ve gotten most of the template functioning and have a way to deploy though I’m still missing two things.

  1. What exactly is the cross compiler used for the RoboRIO? I found this github repo GitHub - wpilibsuite/roborio-toolchain: GCC cross-compiler toolchain for roboRIO that contains the compilers but I can’t find any exact info as to what cross compiler I should use as I’d prefer to just download it from a Linux distro’s package manger rather then setting up something custom, as far as I can tell it uses an arm-eabi processor but if anyone has any extra information it would be very nice.

  2. Is there a RoboRIO emulator or some way I can run code cross compiled for the RoboRIO on a Linux machine to verify that the template is functioning?

For your 2nd question, GitHub - robotpy/roborio-vm: Scripts to create QEMU virtual machine from the RoboRIO image file</t will get you some of the way there. You won’t be able to do anything about the FPGA.

1 Like

That is the correct repo link for the cross-compiler we build for the RIO. I would highly recommend you use this pre-built compiler, as it contains the right sysroot for the RIO (e.g. headers and libraries) and exactly matches the GCC version on the RIO as well, so libc matches. You can drop it anywhere and point your PATH/cmake toolchain file to it. Using a system package cross GCC might work but is definitely not supported, and will likely have versioning issues (e.g. need a newer libc than what is installed on the RIO). If you still want to try it, in terms of the CPU, we build GCC with --with-cpu=cortex-a9 --with-float=softfp --with-fpu=vfpv3.


Thank you! that’s exactly what I was looking for

One more thing: if you’re rolling your own compiler and using WPILib, our GCC pre-defines __FRC_ROBORIO__. That’s used in a handful of places in WPILib to detect whether the build is a RIO target or a simulation target.

OP, be sure to share results. Maybe you can get something interesting working with musl?

ok, one more question, when installing the roborio compiler should I use the bin/ and lib/ folders in the root of the archive or the ones contained inside arm-frc2021-linux-gnueabi/? I’d prefer to use the ones in the root as they have custom names so they won’t conflict with the default compilers on the system but the in the arm folder appears to contain all the includes you were talking about?

Use the ones in the root. The ones in the internal container are called from the ones in the root (this is a standard cross GCC thing).

ok thank you, this is one of my first times cross compiling c++ code

1 Like

here is my current toolchain file after installing everything


set(CMAKE_SYSROOT /usr/arm-frc2021-linux-gnueabi)

set(CMAKE_C_COMPILER /bin/arm-frc2021-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER /bin/arm-frc2021-linux-gnueabi-g++)

I’m trying to compile wpilib using this file to get around an error of it not existing but I’m getting and error saying that it can’t file the x11 libraries, would I have to cross compile the x11 libraries myself or is there an option to compile headless so that I won’t need them?(and if I do cross compile would it be easier to use it with wayland?)

Our cmake build setup for allwpilib isn’t designed to target the Rio. It’s designed for simulation use cases (e.g. local desktop builds, or with the Pi or other coprocessor). While you can disable the parts that are desktop targeted (-DWITH_GUI=OFF), there’s still a pretty big hill to climb, as to build the main part of wpilib, you need cscore, and cscore needs OpenCV. We cross-build OpenCV for the Rio in a different repository. In addition, the cmake allwpilib build doesn’t build the Rio HAL, so you’ll have to modify the build files to do that as well.

My recommendation if you’re trying to use this to build robot programs is to not try to build allwpilib using cmake, but rather grab the various libraries and headers you need from artifacts in the WPILib Maven repository. You’ll need wpiutil, wpimath, ntcore, cscore, cameraserver, hal, wpilibc, opencv (under thirdparty), and ni-libraries. The artifacts are just zip files–for each library, there’s a zip file with the headers and a zip file with each of the library types (e.g. debug shared, release static) for each target platform (the Rio platform name is “athena”). For example, the 2021.3.1 version of wpiutil has this headers artifact and this Rio shared lib artifact.

Have you decided whether you are building shared or static? To keep executable sizes down, GradleRIO builds with shared libraries, but note that means you have to deploy the shared libraries to the Rio as well as the executable.

The plan was it build with static to start just for simplicity but then move to shared, unless the shared libs are already on the rio

I take it there is no single zip in the artifactory that contains all of the libs?

No there is not.

… so why not use the standard gradle-based build? I mean, gradle sucks and all, but it seems easier than rolling your own?

FYI, 5499 and 973 did some CMake stuff just using the provided toolchain. Nothing wrong with depending on its installation or bundling it with your code.

Well that’s the thing, I find that gradle abstracts too much making it difficult to understand just what’s going on under the hood. this is defiantly more of a teaching though assuming it works correctly I’d definitely want to use it

if you’d like to contribute some ideas this repo is where I’m trying it out, if everything goes as planned I’ll create a new repo that’s just the template GitHub - rr1706/Control2021ReverseEngi: A reverse engineering of the 2021 control code

Currently the issue I’m having it that after compiling wpilib using the toolchain file(see the process in the scripts/ the find_package(wpilib REQUIRED) command in cmake still can’t find it(though it does install the files) the files are installed in the wrong place for cmake to find them

Do the cross compiler docker containers contain the wpilib libraries for cross compiling? docker-images/Dockerfile.2020 at main · wpilibsuite/docker-images · GitHub I’m inspecting the output of the commands in them currently to see if it contains the needed artifacts for cross compiling with wpilib but I thought you might know?