Overview
Colcon is the build tool used in ROS2 to build packages. It handles dependencies, parallel builds, and workspace management.Basic commands
Build workspace
- Builds all packages in
src/ - Installs to
install/ - Creates
build/andlog/directories - Uses all available CPU cores
Build with symlink install
- Creates symlinks instead of copying files
- Changes to Python scripts and launch files take effect immediately
- No rebuild needed for non-compiled changes
- Used by the
cbalias
Clean and build
- After changing CMakeLists.txt
- After changing package.xml
- When build is corrupted
- When switching branches with different dependencies
Build options
Build specific packages
Build package and dependencies
Skip packages
Continue on error
Parallel build options
Limit parallel workers
- Limited RAM (reduce workers to avoid OOM)
- Limited CPU cooling
- To reduce system load
Single-threaded build
- Debugging build issues
- Very limited resources
CMake options
Build type
Release: Optimized, no debug symbols (recommended for production)Debug: Debug symbols, no optimization (for debugging)RelWithDebInfo: Optimized with debug symbolsMinSizeRel: Optimized for size
Export compile commands
Custom CMake arguments
Output options
Verbose output
Less verbose output
Log to file only
Test commands
Build with tests
Build without tests
Run tests
Test specific package
Show test results
Verbose test results
Workspace information
List packages
List with paths
List packages topologically
List packages by name pattern
Advanced usage
Build with sanitizers
Custom install prefix
./install
Custom build directory
./build
Merge install
Common workflows
Full clean rebuild
Quick incremental build
Build single package for testing
Debug build with verbose output
Production release build
Environment sourcing
After building, source the workspace:Source workspace
Check sourced workspace
/workspace/turtlebot3_ws/install.
Source in every terminal
Add to~/.bashrc (already done by post-create.sh):
Build logs
Log locations
View build logs
View package-specific logs
View test logs
Troubleshooting
Build fails with no clear error
Try verbose output:CMake cache issues
Clean build directory:Package not found after build
Source the workspace:Dependency issues
Update dependencies:Out of memory during build
Limit parallel workers:Symlink issues on Windows
Don’t use symlink install:Performance tips
Use ccache
Install ccache for faster rebuilds:~/.bashrc:
Limit memory usage
Use mold linker
For faster linking:Integration with aliases
Thecb alias is defined as:
Common colcon arguments
| Argument | Description |
|---|---|
--symlink-install | Use symlinks instead of copying files |
--packages-select | Build only specified packages |
--packages-up-to | Build package and dependencies |
--packages-skip | Skip specified packages |
--parallel-workers N | Limit parallel jobs to N |
--cmake-args | Pass arguments to CMake |
--event-handlers | Control output verbosity |
--continue-on-error | Don’t stop on first error |
--build-base | Custom build directory |
--install-base | Custom install directory |