Ask Your Question
0

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.

Snake_Controller.cpp

#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>
{
public:
  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();
   joint_.setCommand(error*gain_);
 }

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

private:
   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.

CMakeLists.txt

    cmake_minimum_required(VERSION 2.8.3)
    project(my_snake_robot)
    ## 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
    roscpp
    rospy
    controller_interface
    hardware_interface
    pluginlib
    roslib
    )
    catkin_package(
    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@example.com">Jane Doe</maintainer> -->
  <maintainer email="dsong@todo.todo">dsong</maintainer>

  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>controller_interface</build_depend>
  <build_depend>hardware_interface</build_depend>
  <build_depend>pluginlib</build_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>roslib</build_depend>
  <build_export_depend>controller_interface</build_export_depend>
  <build_export_depend>hardware_interface</build_export_depend>
  <build_export_depend>pluginlib</build_export_depend>
  <build_export_depend>roscpp</build_export_depend>
  <build_export_depend>roslib</build_export_depend>
  <exec_depend>controller_interface</exec_depend>
  <exec_depend>hardware_interface</exec_depend>
  <exec_depend>pluginlib</exec_depend>
  <exec_depend>roscpp</exec_depend>
  <exec_depend>roslib</exec_depend>

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

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 ...
(more)
edit retag flag offensive close merge delete

Comments

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 imagePeteBlackerThe3rd ( 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 imageJinhyeokSong ( 2018-08-23 02:05:49 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 195 times

Last updated: Aug 23 '18