ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

CMakeError: make -j4 -l4 error (undefined reference error)

asked 2018-08-22 07:11:10 -0500

JinhyeokSong gravatar image

updated 2018-08-23 13:37:48 -0500

jayess gravatar image

Hello, all. I'm running Ubuntu 16.04 LTS Xenial with ROS kinetic. I tried to make a snake robot following robotignite academy course. However, I've met this kind of error and I don't know how to solve this. Actually, my cpp file does not work as expected. I expect that my problem is on CMakeLists.txt.


#include <controller_interface/controller.h>
#include <hardware_interface/joint_command_interface.h>
#include <pluginlib/class_list_macros.h>

namespace controller_ns{
class PositionController : public controller_interface::Controller<hardware_interface::EffortJointInterface>
  bool init(hardware_interface::EffortJointInterface* hw, ros::NodeHandle &n)
     std::string my_joint;
      if (!n.getParam("joint", my_joint)){
         ROS_ERROR("Could not find joint name");
         return false;
     joint_ = hw->getHandle(my_joint);  // throws on failure
     return true;

 void update(const ros::Time& time, const ros::Duration& period)
   double error = setpoint_ - joint_.getPosition();

 void starting(const ros::Time& time) { }
 void stopping(const ros::Time& time) { }

   hardware_interface::JointHandle joint_;
   static const double gain_ = 2.25;
   static const double setpoint_ = 1.00;
PLUGINLIB_EXPORT_CLASS(controller_ns::PositionController, controller_interface::ControllerBase);

In fact, the cpp code is same as robotigniteacademy ros control101 course's exercise. However, I'm trying to make my code work on my local environment changing CMakeLists.txt.


    cmake_minimum_required(VERSION 2.8.3)
    ## Find catkin macros and libraries
    ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
    ## is used, also find other catkin packages
    find_package(catkin REQUIRED COMPONENTS
    INCLUDE_DIRS include
    LIBRARIES my_snake_robot
    CATKIN_DEPENDS roscpp controller_interface hardware_interface pluginlib roslib

    ## Build ##

    ## Declare a C++ library
    add_library(my_snake_robot_lib src/snake_controller.cpp)

    ## Add cmake target dependencies of the library
    ## as an example, code may need to be generated before libraries
    ## either from message generation or dynamic reconfigure
    add_dependencies(${my_snake_robot} ${${my_snake_robot}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

    ## Declare a C++ executable
    ## With catkin_make all packages are built within a single CMake context
    ## The recommended prefix ensures that target names across packages don't collide
    add_executable(${my_snake_robot}_node src/snake_controller.cpp)

    target_link_libraries(my_snake_robot_lib ${catkin_LIBRARIES})

package.xml <package format="2"> <name>my_snake_robot</name> <version>0.0.0</version> <description>The my_snake_robot package</description>

  <!-- One maintainer tag required, multiple allowed, one person per tag -->
  <!-- Example:  -->
  <!-- <maintainer email="">Jane Doe</maintainer> -->
  <maintainer email="dsong@todo.todo">dsong</maintainer>


  <!-- The export tag contains other, unspecified, tags -->
    <controller_interface plugin="${prefix}/controller_plugins.xml"/>

I'm trying to make adding controller on my unit snake robot. However, it does not work as I expected. Any help will very grateful for me. Thanks for reading.

I've gotten this kind of error

CMake Warning at /opt/ros/kinetic/share/catkin/cmake/catkin_package.cmake:166 (message):
catkin_package() DEPENDS on 'gazebo' but neither 'gazebo_INCLUDE_DIRS' nor
 'gazebo_LIBRARIES' is defined.
 Call Stack (most recent call first ...
edit retag flag offensive close merge delete


Are you trying to build an executable node which depends on a library which is built in this same package? This may be causing you some problems.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-08-22 08:20:22 -0500 )edit

Thanks for giving advice. I'll check for my codes if I wrote something wrong from libraries.

JinhyeokSong gravatar image JinhyeokSong  ( 2018-08-23 02:05:49 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-08-23 05:51:09 -0500

I've just had a closer look at your CMakeLists.txt file and I think you haven't defined the target link libraries for the executable. you have the following line which sets them for the libraries:

target_link_libraries(my_snake_robot_lib ${catkin_LIBRARIES})

But you need to add another line as below to add them for the executable as well:

target_link_libraries(${my_snake_robot}_node ${catkin_LIBRARIES})

This should get this package building properly.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-08-22 07:11:10 -0500

Seen: 632 times

Last updated: Aug 23 '18