Interbotix / interbotix_ros_core

Core ROS Packages for Interbotix Robots
BSD 3-Clause "New" or "Revised" License
30 stars 57 forks source link

Fix linker error `undefined reference: YAML::...` #38

Closed yushijinhun closed 4 months ago

yushijinhun commented 4 months ago

I'm getting ld.lld: error: undefined reference: YAML::... error when compiling packages that depend on interbotix_xs_sdk such as interbotix_xsarm_joy:

ld.lld: error: undefined reference: YAML::LoadFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
>>> referenced by /home/yushijinhun/ws_lsg_locobot/devel/.private/interbotix_xs_sdk/lib/libinterbotix_xs_sdk.so (disallowed by --no-allow-shlib-undefined)

ld.lld: error: undefined reference: YAML::InvalidNode::~InvalidNode()
>>> referenced by /home/yushijinhun/ws_lsg_locobot/devel/.private/interbotix_xs_sdk/lib/libinterbotix_xs_sdk.so (disallowed by --no-allow-shlib-undefined)

...

This PR fixes the linker error.

lukeschmitt-tr commented 4 months ago

What Ubuntu version and what ROS distro are you running where you see this issue?

yushijinhun commented 4 months ago

I'm using ROS Noetic on Ubuntu 20.04. The problem only occurs when I'm using LLVM toolchain. Here's my CMake arguments:

- -DCMAKE_C_COMPILER=clang-18
- -DCMAKE_CXX_COMPILER=clang++-18
- -DCMAKE_CXX_FLAGS=-Wno-enum-constexpr-conversion -fuse-ld=lld-18
- -DCMAKE_C_FLAGS=-fuse-ld=lld-18

The reason of the error is that libinterbotix_xs_sdk does not have libyaml-cpp.so as its dependency, although it uses libyaml-cpp. You can check this with ldd devel/lib/libinterbotix_xs_sdk.so. It works because the program using libinterbotix_xs_sdk happens to depend on libyaml-cpp, but this is not guaranteed. I think it's better to fix this dependency problem, even only few people would encounter this issue.

lukeschmitt-tr commented 4 months ago

We do not have the LLVM toolchain installed here so I am unable to reproduce your issue. However, this change does not seem to affect the build or functionality of the xs_sdk. I'll approve this PR for your edge use case.