Overview
WPILib uses CMake as its build system for C++ projects. This guide covers setting up a C++ robot project from scratch.Prerequisites
- C++20 compatible compiler
- CMake 3.21 or higher
- WPILib installation
- Appropriate toolchain for your platform
Project Structure
A typical WPILib C++ project has the following structure:CMake Configuration
Basic CMakeLists.txt
Based on the WPILib source configuration:WPILib Dependencies
Find and link WPILib packages:Build Options
Standard Build Types
WPILib supports several build configurations:- Debug: Full debug symbols, no optimization
- Release: Optimized, no debug symbols
- RelWithDebInfo: Optimized with debug symbols (default)
- MinSizeRel: Optimized for size
Sanitizer Builds (Development)
For debugging:Building
scp robotProgram [email protected]:/home/lvuser/
Compiler Requirements
C++ Standard
WPILib requires C++20:MSVC Configuration
For Visual Studio:Output Directories
Configure output paths:Optional Components
Enable Vision (cscore)
For camera support:Enable Testing
IDE Integration
VS Code
Create.vscode/c_cpp_properties.json:
CLion
CLion automatically detects CMake projects. Just open the project root.Common Build Commands
Clean build
Parallel build
Install to system
Troubleshooting
CMake Issues
- Ensure CMake 3.21+ is installed:
cmake --version - Clear CMake cache:
rm -rf build/CMakeCache.txt - Regenerate build files:
cmake --build . --clean-first
Compiler Errors
- Verify C++20 support in your compiler
- Check WPILib installation path
- Ensure all dependencies are installed
Cross-compilation Issues
- Verify toolchain file path
- Check roboRIO sysroot installation
- Ensure network connection to roboRIO
Next Steps
- Basic Robot Program - Create your first robot program
- Motor Control - Control motors
- Sensors - Read sensor data