Eric Cousineau
Eric Cousineau

Reputation: 2004

Why do I get linker errors when I build a CMake project using Drake, but I can clearly see the symbols?

I have followed the Installation and Quickstart instructions, and am writing a CMake project to use Drake.

I'm looking at a unittest that builds in Drake, run it, and it builds, runs, and passes. However, when I try to use some of that functionality in my CMake project, I get a linker error, such as:

undefined reference to `RigidBodyTree<double>::get_position_name(int) const'

If I look at symbols in the Drake shared library (e.g. nm -C or objdump -TC with grep), I see the signature RigidBodyTree<double>::get_position_name[abi:cxx11](int). However, if I look in the produced object code (which causes the linking to fail), I see RigidBodyTree<double>::get_position_name(int).

(Note: This post is a means to migrate from http://drake.mit.edu/faq.html to StackOverflow for user-based questions.)

Upvotes: 0

Views: 119

Answers (1)

Eric Cousineau
Eric Cousineau

Reputation: 2004

This is most likely due to an incompatibilty between the compiler used to produce Drake (e.g. clang) and the compiler that CMake has selected (e.g. gcc-4.9). Specifically, gcc-4.9 or before does not tend to handle the DualABI well when linking against clang-compiled code (ref). You may be able to use other functions, because only functions that return an ABI-dependent class (e.g. std::string) are tagged with the ABI that they are using (since they cannot be distinguished in the function signature).

The fix is to change the compiler CMake is using. One way to do this is to set the CC and CXX environment variables to use a supported compiler. For a list of supported compilers, see Supported Configurations. If you are using pre-compiled binaries, please refer to Binary Packages for the compilers used.

WARNING: Do NOT change the compiler using update-alternatives in Ubuntu, as this may affect your DKMS module compatibility with the kernel (among other things) (ref).

Upvotes: 2

Related Questions