Ask Your Question

eclipse and catkin_make not linking to ros.h dependencies

asked 2016-01-21 11:26:04 -0500

Wagner2x gravatar image

updated 2016-01-21 13:11:22 -0500

Hello all,

So I am working on a project where I basically want to create a node to take information from another, check it, then publish that information elsewhere. I was working on it yesterday and my coding environment was working fine(eclipse mars) however at one point yesterday it stopped recognizing all of my references to ros functions or message types. I thought it was just an eclipse specific thing so I tried to run it with catkin_make in my catkin workspace and that threw the same "undefined reference to ros*" errors as the build did in eclipse. Like I said, all was fine and dandy but now it isn't working. Below is the code for the node I am working with.

#include <ros/ros.h>
#include "/opt/ros/indigo/include/ros/ros.h"
#include <std_msgs/String.h>
#include <geometry_msgs/Twist.h>
#include <string>
#include <vector>

/// ROS node name
const std::string ComponentName = "vel_cmd_filter_node";

const std::string J5CommandTopic = "/j5_cmd";
const std::string MoveBaseCmd = "/cmd_vel";

/// default forward linear velocity command in m/s
const float DefaultVelocityCmd = 0.0;

/// default angular velocity command in rad/s
const float DefaultTurnRateCmd = 0.0;

 /// the rate at which the component will publish commands
const int LoopRate = 10; // Hz

/// input value limits
/// these are just here for safety and do not reflect the actual limits of the platform
const double MaxVelocityCommand = 3.0;
const double MaxTurnRateCommand = 1.0;

geometry_msgs::Twist incoming;

void chatterCallback(const geometry_msgs::Twist& velcmd);
geometry_msgs::Twist getCommandMsg();

int main(int argc, char **argv) {

// get all command line arguments that aren't ROS specific
// these should be the velocity command parameters

// initialize ROS
std::vector<std::string> args;
geometry_msgs::Twist velcmd;

ros::init(argc,argv, ComponentName);
ros::removeROSArgs(argc, argv, args);
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe(MoveBaseCmd, 1000, chatterCallback);

// velocity command publisher
ros::Publisher velCmdPub = nh.advertise<geometry_msgs::Twist>(J5CommandTopic, 1000);

// asynchronous spinner to receive ROS messages
ros::AsyncSpinner spinner(0);

// loop rate used to control the frequency of message publication
ros::Rate loop_rate(LoopRate);

// set up message command
geometry_msgs::Twist cmdMsg = getCommandMsg();

// run loop
while (ros::ok()) {

    // publish velocity command
    ROS_INFO("Sending Velocity Command: {%f, %f}", cmdMsg.linear.x,
    if (cmdMsg.linear.x || cmdMsg.angular.z) {

// shutdown component

return 0;

void chatterCallback(const geometry_msgs::Twist& velcmd) {
ROS_INFO("I heard this velocity: [%f]", velcmd.linear.x);
ROS_INFO("I heard this rotation: [%f]", velcmd.angular.z);
incoming = velcmd;

geometry_msgs::Twist getCommandMsg() {

geometry_msgs::Twist msg;

// body coordinates
// x is forward linear motion
msg.linear.x = DefaultVelocityCmd;

// rotation around the Z axis
msg.angular.z = DefaultTurnRateCmd;

// all other parameters are ignored in the Twist message
// NOTE:: args[0] is the name of the
if (incoming.linear.x) {
    try {
        msg.linear.x = incoming.linear.x;
        msg.linear.x = std::max(msg.linear.x, -MaxVelocityCommand);
        msg.linear.x = std::min(msg.linear.x, MaxVelocityCommand);

    catch (...) {
        // could not parse the input, use default value
        msg.linear.x = DefaultVelocityCmd;

if ...
edit retag flag offensive close merge delete


Your CMakeLists.txt is the build file, which controls linking. Please edit your question to include your CMakeLists.txt

ahendrix gravatar image ahendrix  ( 2016-01-21 12:30:13 -0500 )edit

Also, +1 for good formatting on your first post :)

ahendrix gravatar image ahendrix  ( 2016-01-21 12:30:31 -0500 )edit

The cmake file wouldn't affect the build in eclipse though right? or am I crazy

Wagner2x gravatar image Wagner2x  ( 2016-01-21 13:02:59 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-01-21 13:34:18 -0500

ahendrix gravatar image

I'm not completely familiar with eclipse, but I presume that it uses the build rules defined in the CMakeLists.txt or that cmake generates the eclipse project, based on the CMakeLists.txt.

Either way, your CMakeLists.txt is missing the command which links your program against the ROS libraries. As described in the C++ publisher tutorial, section 1.3) and elsewhere, you need to add a target_link_libraries() to your CMakeLists.txt, like:

target_link_libraries(vel_cmd_filter_node ${catkin_LIBRARIES})

I'm not sure why it was working before; perhaps that line was there and you accidentally deleted it from the end of the file?

edit flag offensive delete link more


Sweet! Thanks! that worked for the catkin_make but Im still confused as to why eclipse still isn't recognizing the ros functions.

Wagner2x gravatar image Wagner2x  ( 2016-01-21 13:56:23 -0500 )edit

I should probably specify that I have an eclipse project elsewhere(not in my catkin_ws directory) and I am using that to develop the source file and then just copying the src file to the source directory in my catkin_ws

Wagner2x gravatar image Wagner2x  ( 2016-01-21 14:09:15 -0500 )edit

I don't use Ecplise and don't know much about it, but this page describes how to use Ecplise and other IDEs with catkin: . Probably much better than copying files back and forth.

ahendrix gravatar image ahendrix  ( 2016-01-21 15:39:30 -0500 )edit

Thanks for the help! Sorry I took so long to reply. It builds fine now however it is not publishing the information correctly. Should I start a new question or is that something you could answer here?

Wagner2x gravatar image Wagner2x  ( 2016-02-01 10:22:48 -0500 )edit

I think that would be better as a new question.

ahendrix gravatar image ahendrix  ( 2016-02-01 11:20:06 -0500 )edit

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


Asked: 2016-01-21 11:26:04 -0500

Seen: 254 times

Last updated: Jan 21 '16