Catkin unable to include custom libraries
報錯內容:
/home/firefly/eai_ws/src/square/square_goal_service/src/service_server.cpp:3:53:
fatal error: square_goal_service/square_goal_service.h: No such file or directory
沒有那個文件或目錄
#include <square_goal_service/square_goal_service.h>
首先查找頭文件(file)是否存在
You should create a folder named include/ < name of package > / (include/proj_utils in your case) where you put all the header files (*.hpp) of the package.
但是實際上該文件是存在的,那麼查看是否告訴了編譯器文件的路徑!
其次路徑是否設置正確(directory)
Then the package that exports the library should have the following in the CMakeLists to be able to export the header files:
catkin_package(
LIBRARIES visionutil rosutil
INCLUDE_DIRS include)
include_directories(
include
${catkin_INCLUDE_DIRS})
再次在src源碼中調用xx.h文件方式是否正確
正確:
#include <name_of_package/header_file.h>
錯誤:
#include <header_file.h>
以上三個步驟也是在ROS中創建.h頭文件的流程!
1.創建頭文件,具體文件路徑如下include/ < name of package > / (include/proj_utils in your case) ,/include與/src同一層級均在package下一級;
2.添加路徑,修改CMakeLists,在catkin_package和include_directories中分別添加INCLUDE_DIRS include和include;
3.引用頭文件,在應用代碼中添加頭文件,#include <name_of_package/header_file.h>
參考文獻:
https://answers.ros.org/question/195467/catkin-unable-to-include-custom-libraries/