0

I am a starter of drake. I use urdf parser to extract my robot model to RigidBodyTree. Then I use doKinematics function to create kinematic cache. However, the builder give me the error below.
This is one case, in some cases, I cannot use other functions in the file rigid_body_tree.cc, and errors are almost the same one.

  • OS:Ubuntu 16.04
  • Language: C++ -GCC 5.4.0 -Clang 6.0.0 -Python 2.7.12
  • Built from source
    • Bazel 0.28.1
    • Bazel C++ compiler +capture_cc_env=external/drake/tools/cc_toolchain/capture_cc.env +source external/drake/tools/cc_toolchain/capture_cc.env ++BAZEL_CC=/usr/bin/gcc ++BAZEL_CC_FLAGS= +/usr/bin/gcc --version gcc (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609
    • Git revision: 800d961
    • Build drake using the method on the first page of drake document, "installation and quickstart
auto tree = new RigidBodyTree<double>();  
Eigen::Matrix<double, 9, 1> q_in, qd_in;  
q_in << 1, 2, 3, 4, 5, 6, 7, 8, 9;  
qd_in << 1, 2, 3, 4, 5, 6, 7, 8, 9;  
auto kinematics = tree->doKinematics(q_in, qd_in);

Error info:
test.pic.o:test.cpp:function main: error: undefined reference to 'KinematicsCache<Eigen::Matrix<double, 9, 1, 0, 9, 1>::Scalar> RigidBodyTree<double>::doKinematics<Eigen::Matrix<double, 9, 1, 0, 9, 1>, Eigen::Matrix<double, 9, 1, 0, 9, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, 9, 1, 0, 9, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, 9, 1, 0, 9, 1> > const&, bool) const'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Ken White
  • 123,280
  • 14
  • 225
  • 444
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – L. F. Jul 25 '19 at 00:44
  • Possible duplicate of [Why can templates only be implemented in the header file?](https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file) – chtz Jul 25 '19 at 10:50
  • Great! Thank you! – Junda Huang Jul 26 '19 at 01:02

1 Answers1

2

You can change

Eigen::Matrix<double, 9, 1> q_in, qd_in; 

to

Eigen::VectorXd q_in(9);
Eigen::VectorXd qd_in(9); 

The problem is that we explicitly instantiate the template for doKinematics in https://github.com/RobotLocomotion/drake/blob/004864a1ef09583754b8573f287fd2658d18aab3/attic/multibody/rigid_body_tree.cc#L3878-L3884, and it doesn't include the template with type Eigen::Matrix<double, 9, 1>. Hence the linker cannot find a reference. But we do instantiate the template with type Eigen::VectorXd.

BTW, RigidBodyPlant is deprecated. We recommend the user to try MultibodyPlant instead.

Hongkai Dai
  • 2,546
  • 11
  • 12