{"id":14497,"library":"colcon-pkg-config","title":"colcon-pkg-config","description":"colcon-pkg-config is a colcon extension that provides an environment hook to correctly set the `PKG_CONFIG_PATH` during `colcon build` operations. It ensures that `share/pkgconfig` directories of previously installed packages within the workspace are added to `PKG_CONFIG_PATH`, making `pkg-config` files discoverable for subsequent builds. The current version is 0.1.0, and its release cadence is infrequent, typically aligning with colcon core developments or specific ROS releases.","status":"active","version":"0.1.0","language":"en","source_language":"en","source_url":"https://github.com/colcon/colcon-pkg-config/","tags":["colcon","build-system","robotics","ROS","pkg-config","environment-variables","plugin"],"install":[{"cmd":"pip install colcon-pkg-config","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"This package is an extension for colcon-core and requires it to function.","package":"colcon-core","optional":false}],"imports":[],"quickstart":{"code":"# colcon-pkg-config is a colcon extension and does not provide direct Python APIs for userland code.\n# Its functionality is automatically integrated into the 'colcon build' process once installed.\n\n# To use:\n# 1. Install colcon-pkg-config in the same Python environment as colcon-core:\n#    pip install colcon-pkg-config\n\n# 2. Set up a colcon workspace with packages that produce and consume .pc files.\n#    For example, 'pkg_a' installs 'libpkg_a.pc' and 'pkg_b' uses 'pkg-config --cflags --libs libpkg_a'.\n#    mkdir -p my_colcon_ws/src/pkg_a\n#    mkdir -p my_colcon_ws/src/pkg_b\n#    # (populate pkg_a's CMakeLists.txt to install a .pc file to share/pkgconfig)\n#    # (populate pkg_b's CMakeLists.txt to use find_package(PkgConfig) and pkg_check_modules(libpkg_a ...))\n\n# 3. Build your colcon workspace from the root of 'my_colcon_ws':\n#    import os\n#    if os.path.exists('src'): # Simulate running in a colcon workspace\n#        print('Building colcon workspace. colcon-pkg-config will automatically augment PKG_CONFIG_PATH.')\n#        # This conceptual command would be run in a shell:\n#        # os.system('colcon build --symlink-install')\n#    else:\n#        print('Please run this conceptual quickstart within a colcon workspace root.')\n\n# The extension ensures that pkg_b correctly finds pkg_a's .pc file without manual PKG_CONFIG_PATH setup.","lang":"python","description":"colcon-pkg-config is a plugin, not a library with direct user-facing Python imports or functions. Its quickstart involves installation and then simply running `colcon build` within a workspace, where it automatically enhances the build environment. The example above illustrates the conceptual steps, as `colcon build` is a shell command."},"warnings":[{"fix":"Ensure `pip install colcon-pkg-config` is executed in the exact same Python environment where `colcon` is installed and active.","message":"colcon-pkg-config must be installed in the same Python environment (e.g., virtual environment or system Python) as your colcon-core installation for it to be discovered and activated. If they are in separate environments, the extension will not function.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Install the `pkg-config` utility via your system's package manager (e.g., `sudo apt install pkg-config` on Ubuntu/Debian, `brew install pkg-config` on macOS, `dnf install pkg-config` on Fedora).","message":"This extension only augments the `PKG_CONFIG_PATH` environment variable during the `colcon build` and `colcon install` steps. It does not ensure `pkg-config` itself is installed or in your system's PATH. If `pkg-config` is missing, you will still encounter errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For packages within a colcon workspace, rely on `colcon-pkg-config`. If external `pkg-config` paths are needed, consider managing them through a colcon `environment` hook or by sourcing environment setup files *before* your workspace's `setup.bash`.","message":"When manually setting `PKG_CONFIG_PATH` in your shell, be aware that colcon-pkg-config will prepend workspace-specific paths. Depending on the order of precedence and how `pkg-config` resolves paths, your manual settings might be ignored or interfere with the automated ones. It's generally best to let colcon manage this path for workspace-internal dependencies.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Verify that the package providing 'my_lib' has been successfully built and installed (or symlinked) *before* the package attempting to use it. Confirm `colcon-pkg-config` is installed correctly in the same environment as `colcon`. Ensure `pkg-config` itself is installed on your system.","cause":"During a `colcon build`, `pkg-config` failed to locate the `.pc` file for 'my_lib'. This often means the package providing 'my_lib' was not built/installed yet, `colcon-pkg-config` is not active, or `pkg-config` cannot find the `install/share/pkgconfig` directory.","error":"Package 'my_lib' not found"},{"fix":"As above, check the build order of your packages, ensure `colcon-pkg-config` is properly installed, and confirm `pkg-config` is available on your system. Sometimes cleaning and rebuilding the workspace (`colcon build --merge-install --cmake-args -DCMAKE_BUILD_TYPE=Release`) can resolve transient issues.","cause":"This is a common CMake error indicating that `pkg-config` (which CMake uses via `FindPkgConfig`) failed to find a required dependency's `.pc` file. This is the underlying CMake manifestation of the 'Package not found' issue.","error":"CMake Error at /usr/share/cmake-X.Y/Modules/FindPkgConfig.cmake:NNN (message): A required package was not found."}],"ecosystem":"pypi"}