Ask Your Question
0

Import message from a different directory into a cpp script [closed]

asked 2021-05-06 10:36:26 -0500

RB_Code gravatar image

In my workspace inside the test folder I have a msg folder that contains a message testmessage.msg.

Now I'm trying to subscribe to the topic in a cpp script in a different folder, for example test2 , only when I do the include it says it can't find it.

In python I import like this and it works:

from test.msg import testmessage

How can I import in cpp?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by RB_Code
close date 2021-05-07 03:51:09.567085

Comments

I have this error when importing in cpp script:

fatal error: r2d2/Charger.h: No such file or directory
 #include "r2d2/Charger.h"

Charge.msg is in the r2d2 folder which is in my carkin_ws so in CMakelist I put it:

link_directories(/home/pc/catkin_ws/src/r2d2)
RB_Code gravatar image RB_Code  ( 2021-05-06 17:04:51 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-05-06 12:04:23 -0500

abhishek47kashyap gravatar image

In C++, you'd import the header file for that message like so:

#include "package_name/msg_name.h"

So in your case: #include "test/testmessage.h"


From Writing Publisher C++ code explained:

#include "std_msgs/String.h"

This includes the std_msgs/String message, which resides in the std_msgs package. This is a header generated automatically from the String.msg file in that package.

edit flag offensive delete link more

Comments

Yes I tried that way but it says it can't find the package .

Could I have to add something in CMakelist and am I forgetting?

RB_Code gravatar image RB_Code  ( 2021-05-06 12:59:33 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-05-06 10:36:26 -0500

Seen: 32 times

Last updated: May 06