Build ROS 2 Jazzy workspace using colcon. Use when asked to build a package, enable debug symbols, enable coverage instrumentation, compile workspace with specific flags, or perform incremental vs full builds. Supports single-package builds, dependency chains, debug builds, and coverage-enabled compilation.
Build ROS 2 packages efficiently using colcon with support for incremental development builds, full workspace builds, debug symbols, and coverage instrumentation.
scripts/setup.bash available in workspace rootUse for rapid iteration when developing a specific package.
Source the ROS environment:
source scripts/setup.bash
Build the package and its dependencies:
python3 -m colcon build \
--symlink-install \
--event-handlers console_cohesion+ \
--packages-up-to <package_name>
Verify build success by checking build/<package_name>/ and install/<package_name>/ directories
Typical execution time: 2-5 minutes depending on package size
Use when you've only modified internal package code.
Source the ROS environment:
source scripts/setup.bash
Build only the specified package:
python3 -m colcon build \
--symlink-install \
--event-handlers console_cohesion+ \
--packages-select <package_name>
When to use: You know the package's dependencies are already built
Use when you need to debug code execution or attach a debugger.
Source the ROS environment:
source scripts/setup.bash
Build with debug symbols:
python3 -m colcon build \
--symlink-install \
--event-handlers console_cohesion+ \
--packages-up-to <package_name> \
--cmake-args -GNinja -D CMAKE_BUILD_TYPE=Debug
Debug symbols will be available in the build artifacts
Use when preparing to run tests with coverage analysis.
Source the ROS environment:
source scripts/setup.bash
Build with coverage enabled:
python3 -m colcon build \
--symlink-install \
--event-handlers console_cohesion+ \
--packages-up-to <package_name> \
--cmake-args -GNinja -D CMAKE_BUILD_TYPE=Debug -D DRQP_ENABLE_COVERAGE=ON
After running tests, coverage data will be available in build/<package_name>/coverage.info (C++) or .coverage (Python)
WARNING: Full builds take 10-20+ minutes. Only use when explicitly requested or making cross-cutting changes.
Source the ROS environment:
source scripts/setup.bash
Build entire workspace with all optimizations:
export CMAKE_EXPORT_COMPILE_COMMANDS=1
export CC=clang
export CXX=clang++
python3 -m colcon build \
--symlink-install \
--event-handlers console_cohesion+ \
--base-paths "$(pwd)" \
--cmake-args \
-GNinja \
-D CMAKE_BUILD_TYPE=Debug \
-D DRQP_ENABLE_COVERAGE=ON \
--no-warn-unused-cli
Wait for all packages to complete (monitor progress in console)
| Option | Purpose | Example |
|---|---|---|
--packages-up-to <pkg> | Build package and all dependencies | --packages-up-to drqp_serial |
--packages-select <pkg> | Build only specified package | --packages-select drqp_control |
--symlink-install | Use symlinks for Python (faster) | Always recommended |
--event-handlers console_cohesion+ | Cleaner console output | Always recommended |
-GNinja | Use Ninja build system (faster) | -GNinja |
-D CMAKE_BUILD_TYPE=Debug | Build with debug symbols | For debugging |
-D DRQP_ENABLE_COVERAGE=ON | Enable coverage instrumentation | For test coverage |
| Issue | Cause | Solution |
|---|---|---|
| "Command 'colcon' not found" | Environment not sourced | Run source scripts/setup.bash |
| Compilation errors in C++ code | Missing dependencies or code errors | Check log/latest_build/ for details |
| "Package not found" error | Package doesn't exist or wrong name | Verify package name in packages/runtime/ or packages/simulation/ |
| Build takes very long | Full workspace build or large package | Use --packages-select or --packages-up-to for incremental builds |
| "Permission denied" errors | Cannot write to install directory | Check workspace permissions with ls -la install/ |
| Linker errors after changes | Stale build artifacts | Run cleanup: ./scripts/clean.fish then rebuild |
build/<package_name>/install/<package_name>/log/latest_build/build/compile_commands.jsonbuild/<package_name>/coverage.infobuild/<package_name>/.coverage