带黑名单参数运行catkin_make run_tests时遇链接错误求助
catkin_make run_tests Using CATKIN_BLACKLIST_PACKAGES - Cannot Find -lsr_interpolation Problem Breakdown
Let me restate your issue to make sure I've got it right:
- You're working on Ubuntu 16.04 with ROS Kinetic.
- Cloned the
sr-ros-interface-ethercatrepo, checked outF#SRC-2546_new_thumb_calibration_kinetic_devel, and installed all dependencies. - Regular
catkin_makeandcatkin_make run_testswork perfectly with no errors. - But when running the CI build command (with a long
CATKIN_BLACKLIST_PACKAGESlist and coverage flags), you hit a linker error:/usr/bin/ld: cannot find -lsr_interpolation
collect2: error: ld returned 1 exit status
sr-ros-interface-ethercat/sr_robot_lib/CMakeFiles/sr_hand_lib.dir/build.make:504: recipe for target '/home/user/workspace/devel/lib/libsr_hand_lib.so' failed
You mentioned sr_interpolation compiles normally in non-blacklisted builds—so this problem is specific to the blacklisted test run with coverage flags.
Likely Causes
- Blacklisted Package is a Critical Dependency: Your
CATKIN_BLACKLIST_PACKAGESincludessr_interpolation, butsr_hand_lib(which is being built for tests) explicitly depends on it. When you blacklistsr_interpolation, Catkin skips building it—but since you're using new compile flags (--coverageetc.), the existing compiled version ofsr_interpolationdoesn't match the new build context, or the linker can't locate it in the reconfigured environment. - Coverage Flags Require a Full Rebuild: The
--coverageflags change how binaries are compiled and linked. Even ifsr_interpolationwas built before, runningcatkin_make run_testswith new CXX flags triggers a reconfiguration. Sincesr_interpolationis blacklisted, it doesn't get rebuilt with the same coverage flags, so the linker can't find a compatible version oflibsr_interpolation.so. - Catkin Make Dependency Resolution Quirk: ROS Kinetic's
catkin_makehas known limitations with handling blacklists during test runs compared to regular builds. It might not properly resolve transitive dependencies when packages are blacklisted, even if they were built previously.
Solutions to Try
1. Remove sr_interpolation from the Blacklist
Since sr_hand_lib depends on sr_interpolation to link successfully, it shouldn't be in the blacklist. Modify your CI command to exclude sr_interpolation from CATKIN_BLACKLIST_PACKAGES:
catkin_make run_tests -DCATKIN_BLACKLIST_PACKAGES="sr_msgs_common;sr_run_trajectories;sr_logging_common;sr_utilities_common;sr_world_generator;sr_watchdog;sr_description_common;sr_description;sr_common;sr_robot_msgs;sr_dynamic_time_warping;ros_ethercat_eml;sr_ur_arm_config;sr_config;sr_ethercat_hand_config;ros_ethercat_loop;ros_ethercat_model;ros_ethercat_hardware;ros_ethercat;sr_mechanism_controllers;sr_hardware_interface;sr_hand;sr_gazebo_sim;sr_utilities;sr_mechanism_model;sr_core;sr_tactile_sensors" -DCMAKE_CXX_FLAGS=" --coverage -fprofile-arcs -ftest-coverage"
This ensures sr_interpolation is built with the same coverage flags as sr_hand_lib, allowing the linker to find it.
2. Pre-Build sr_interpolation with Coverage Flags
If you absolutely need to keep sr_interpolation in the blacklist (though this doesn't make logical sense given the dependency), pre-build it separately with the coverage flags before running the test command:
# First build sr_interpolation with coverage flags catkin_make --pkg sr_interpolation -DCMAKE_CXX_FLAGS=" --coverage -fprofile-arcs -ftest-coverage" # Then run the blacklisted test command catkin_make run_tests -DCATKIN_BLACKLIST_PACKAGES="sr_msgs_common;sr_run_trajectories;sr_logging_common;sr_utilities_common;sr_world_generator;sr_watchdog;sr_description_common;sr_description;sr_common;sr_robot_msgs;sr_interpolation;sr_dynamic_time_warping;ros_ethercat_eml;sr_ur_arm_config;sr_config;sr_ethercat_hand_config;ros_ethercat_loop;ros_ethercat_model;ros_ethercat_hardware;ros_ethercat;sr_mechanism_controllers;sr_hardware_interface;sr_hand;sr_gazebo_sim;sr_utilities;sr_mechanism_model;sr_core;sr_tactile_sensors" -DCMAKE_CXX_FLAGS=" --coverage -fprofile-arcs -ftest-coverage"
This ensures the correct version of libsr_interpolation.so exists in the devel/lib directory when sr_hand_lib tries to link against it.
3. Switch to catkin build (More Reliable Dependency Handling)
catkin_make is known for less robust dependency management compared to catkin build (from the catkin_tools package). Try using catkin build instead, which handles blacklists and test runs more consistently:
# Install catkin_tools if you haven't already sudo apt-get install ros-kinetic-catkin-tools # Clean previous build artifacts catkin clean # Run tests with blacklist and coverage flags catkin build --blacklist sr_msgs_common sr_run_trajectories sr_logging_common sr_utilities_common sr_world_generator sr_watchdog sr_description_common sr_description sr_common sr_robot_msgs sr_interpolation sr_dynamic_time_warping ros_ethercat_eml sr_ur_arm_config sr_config sr_ethercat_hand_config ros_ethercat_loop ros_ethercat_model ros_ethercat_hardware ros_ethercat sr_mechanism_controllers sr_hardware_interface sr_hand sr_gazebo_sim sr_utilities sr_mechanism_model sr_core sr_tactile_sensors --cmake-args -DCMAKE_CXX_FLAGS=" --coverage -fprofile-arcs -ftest-coverage" --run-tests
Verification Steps
After trying any of the above solutions:
- Clean your workspace with
catkin clean(orcatkin_make clean) to remove old build artifacts. - Re-run the modified CI command.
- Check if the linker error is resolved and the tests run successfully.
内容的提问来源于stack exchange,提问作者Mike_k

