How to call ros functions from an external .cpp or .c file?
Hello All,
I am trying to access some of the ROS functions like ros::init(), ros::ok(), from outside of the CATKIN_WORKSPACE.
ros.h is included by adding
/opt/ros/kinetic/include/ path.
The header file gets linked but when I am trying to access some of the ros functions, it throws errors like : undefined reference to ros::init(); : undefined reference to ros::ok(); etc.
Can I get some suggestion on this issue?
Thank you in advance.
Asked by rama_bhuyan on 2018-05-14 00:26:06 UTC
Answers
Hello rama_bhuyan,
You can have multiples CATKIN_WORKSPACES in your machine, with any name or inside of any directory. However, you won't be able to access the catkin structure if you don't have at least a directory named "src" as something like this: /my_catkin_workspace_in_some_place/src
. In your terminal inside of /my_catkin_workspace_in_some_place/
you'll be able to have access to all ROS libraries using a CMakeLists.txt file and a catkin_make command, this tutorial has some steps to do it.
So if you must build projects outside of a CATKIN_WORKSPACES you'll have to do a lot of code in CMakeLists.txt to find all ROS specific environment variables and setup all libs to your code as the catkin tool already does.
My advice is that you consider using a catkin structure even if your circumstances don't allow it, because in this way you won't build the wheel again as the ROS principles say.
I hope it may help you.
Best regards.
Asked by matheusns on 2018-05-17 08:16:27 UTC
Comments
I could able to execute ROS publisher node, outside of catkin_ws. by adding the ros libraries manually.
Asked by rama_bhuyan on 2018-05-18 05:04:37 UTC
Comments
Hello ,
Can anyone suggest me some solution ?
Asked by rama_bhuyan on 2018-05-17 05:47:04 UTC
If you get this kind of error at the linking stage, it means that the ROS libraries containing the function definitions are not found. What do you mean by "trying to access some of the ROS function outside of CATKIN"? Are you using a Makefile/CMake you created ?
Asked by pokitoz on 2018-05-17 08:01:59 UTC