0

I am trying to compile a .cpp file which uses some of the ROS library functions like "ros/ros.h" , "std_msgs/String.h". In the make file, I have included the path for the respective include files in the include section.

But when I am compiling the .cpp, I am getting errors like:

:Undefined reference to 'ros::init(int&, char**,
std::__cxx11::basic_string<char, std::char_traits<char="">,
std::allocator<char>> const&, unsigned int)'.

Like wise I am getting some other errors like

:Undefined reference to ros::NodeHandle
:Undefined reference to ros::Rate::Rate(double)
:Undefined reference to ros::ok()

etc.

What could be the reason for such errors? How can I overcome these errors?

k_ssb
  • 6,024
  • 23
  • 47
rama
  • 43
  • 2
  • 6
  • 1
    Can you share your code? Usually that happens when you try to invoke a ros function, such as creating a nodeHandle before ros::init() – malintha May 11 '18 at 17:06
  • Thank you Marlio for your response. ros::init() is written at the beginning of the main function. after that only I have created NodeHandle. – rama May 14 '18 at 04:26
  • my query is, when I am trying to compile this code outside of the CATKIN_WORKSPACE, it throws the above mentioned error. my anticipation is even though it finds the header file ROS.H of ros but it could not link with the functions of ros. is there anyway we can link the functions of ros for execution of our program – rama May 14 '18 at 04:30
  • I have never tried to compile a ros code outside of the catkin_workspace though. Whenever you execute the catkin_make command, ros creates a symbolic link in your src directory so that it is aware of your packages. Can't you create a workspace from where your code resides? FInd mode about catkin_make here. http://wiki.ros.org/catkin/commands/catkin_make – malintha May 16 '18 at 04:34
  • I found from [here by @akshayak07](https://stackoverflow.com/questions/50324348/can-a-ros-node-be-created-outside-of-catkin-workspace/50332439?noredirect=1#comment87718164_50332439) ;that *.py* files(which uses ros functions) can run outside of **catkin_ws**. so is there any possibility for .cpp file to run ? in cmake file we have some variables like ${catkin_LIBRARIES} , ${catkin_INCLUDE_DIRS}, where can I find the paths specified to these variables. I think if we can find the exact library path , we can add and try, if .cpp is running or not. – rama May 16 '18 at 09:09
  • But in case of ROS2.0, we can use the functions of ros. where ros2.0 workspace and catkin_ws are two independent entities. – rama May 16 '18 at 10:16
  • But, this isn't `ROS 2.0` , this is `ROS` and features of ROS might be carried over to 2.0, but the converse might not be true. – akshayk07 May 17 '18 at 19:32

1 Answers1

1

Your Problem Is Your Linker Cannot Find libroscpp.so located in /opt/ros/<your-distro>/lib/ You Can Add This Path Manually To Your ldconfig Path

Or You Can Place It Somewhere That Is Already In Your ldconfig path

Mohammad Ali
  • 569
  • 4
  • 10