ros头文件引用
引自:https://blog.csdn.net/wawayu_0/article/details/79410237
1. 如何引用自定义头文件
• 引用当前软件包内的头文件
在包的目录include下建test_pack.h文件
#ifndef _TEST_PKG_
#define _TEST_PKG_
#define TEST_PKG_VER "1.0.0"
#define INIT_COUNT 100
int addTwoNum(int a,int b);
#endif
修改CMakeLists.txt参数
include_directories(
include
${catkin_INCLUDE_DIRS}
)
2.引用别的包的头文件
catkin_package(
INCLUDE_DIRS include
# LIBRARIES test
# CATKIN_DEPENDS roscpp rospy std_msgs
# DEPENDS system_lib
)
将包发布,才能使用。
3.引用动态链接库.so文件
mkdir lib
mkdir include/my_pkg
cd include/my_pkg
nano multiply.h
#ifndef _MULTIPLY_H_
#define _MULTIPLY_H_
#ifdef __cpluscplus
extern "c"
{
#endif
int multiply(int a,int b);
#ifdef __cpluscplus
#endif
#endif
nano multiply.cpp
#include "multiply.h"
int multiply(int a,int b)
{
return a*b;
}
nano my_pkg/src/my_pkg.cpp
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>
#include "test/test_pkg.h"
#include "my_pkg/multiply.h"
int main(int argc, char **argv)
{
ros::init(argc, argv, "example_talker_msg");
ros::NodeHandle n;
ros::Publisher pub = n.advertise<std_msgs::String>("message", 1000);
ros::Rate loop_rate(10);
int count=multiply(30,5);
ROS_INFO("test version:%s,init count:%d",TEST_PKG_VER,INIT_COUNT);
while (ros::ok())
{
std_msgs::String msg;
std::stringstream ss;
ss << "my_pkg" << count;
修改CMakeLists.txt
include_directories(
include
${catkin_INCLUDE_DIRS}
)
link_directories(
lib
${catkin_LIB_DIRS}
)
##
编译
运行
以上确实解决了我的部分问题,但是仍然没有解决我的ROS程序不能引用自定义消息包头文件的问题。