标签:include catkin ROS 笔记 12 cpp 头文件 main hello
ROS中的头文件与源文件
-
头文件
在功能包下的 include/功能包名 目录下新建头文件: hello.h,示例内容如下:
#ifndef _HELLO_H #define _HELLO_H namespace hello_ns{ class HelloPub { public: void run(); }; } #endif
于c_cpp_properties.json文件中配置头文件
-
可执行文件
在 src 目录下新建文件:hello.cpp,示例内容如下:#include "ros/ros.h" #include "test_head/hello.h" namespace hello_ns { void HelloPub::run(){ ROS_INFO("自定义头文件的使用...."); } } int main(int argc, char *argv[]) { setlocale(LC_ALL,""); ros::init(argc,argv,"test_head_node"); hello_ns::HelloPub helloPub; helloPub.run(); return 0; }
-
CMakeLists.txt
需要额外配置,去掉注释即可
include_directories( include ${catkin_INCLUDE_DIRS} )
hello.cpp与main.cpp分开实现
在CMakeLists.txt中配置
add_library(hello
include/test_head_src/hello.h
src/hello.cpp
)
# hello 是为库映射的名字
add_dependencies(hello ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(hello
${catkin_LIBRARIES}
)
add_executable(main src/main.cpp)
add_dependencies(main ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(main
hello
${catkin_LIBRARIES}
)
python
import os
import sys
path = os.path.abspath(".")
# 核心
sys.path.insert(0,path + "/src/plumbing_pub_sub/scripts")
import tools
使用scripts/tools.py模块时,在文件中需要加入的如上
配置与普通python配置没有区别
标签:include,catkin,ROS,笔记,12,cpp,头文件,main,hello 来源: https://www.cnblogs.com/yixinrujiu/p/15902958.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。