Ask Your Question
1

How to call ros functions from an external .cpp or .c file?

asked 2018-05-14 00:26:06 -0600

rama_bhuyan gravatar image

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.

edit retag flag offensive close merge delete

Comments

Hello ,
Can anyone suggest me some solution ?

rama_bhuyan gravatar imagerama_bhuyan ( 2018-05-17 05:47:04 -0600 )edit

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 ?

pokitoz gravatar imagepokitoz ( 2018-05-17 08:01:59 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-05-17 08:16:27 -0600

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.

edit flag offensive delete link more

Comments

I could able to execute ROS publisher node, outside of catkin_ws. by adding the ros libraries manually.

rama_bhuyan gravatar imagerama_bhuyan ( 2018-05-18 05:04:37 -0600 )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

3 followers

Stats

Asked: 2018-05-14 00:26:06 -0600

Seen: 159 times

Last updated: May 17 '18