参考:
https://answers.ros.org/question/195467/catkin-unable-to-include-custom-libraries/
报错内容:
/home/zhanghu/catkin_ws/src/map_img_proccess/src/map_img_load.cpp:1:26: fatal error: map_img_load.h: 没有那个文件或目录
#include "map_img_load.h"
解决办法:
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.
Then the package that exports the library should have the following in the CMakeLists to be able to export the header files:
catkin_package(
INCLUDE_DIRS include
LIBRARIES map_img_load
)
include_directories(
include
${catkin_INCLUDE_DIRS})
Then the other package should be able to see the header files as (you might have to run catkin_make or cmake first):
#include <name_of_package/header_file.h>
完整的CMakeLists.txt:
--------------------------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8.3)
project(map_img_proccess)
find_package(catkin REQUIRED COMPONENTS
roscpp
)
find_package(OpenCV REQUIRED)
catkin_package(
INCLUDE_DIRS include
LIBRARIES map_img_load
# CATKIN_DEPENDS roscpp
# DEPENDS system_lib
)
include_directories(
include
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
add_library(map_img_load src/map_img_load.cpp)
target_link_libraries(map_img_load ${catkin_LIBRARIES} ${OpenCV_LIBRARIES})
add_executable(main src/main.cpp)
target_link_libraries(main map_img_load ${catkin_LIBRARIES} )
--------------------------------------------------------------------------------------------
同时:头文件中有条件编译的千万别忘记最后的#endif
#ifndef ...
#define ...
...
...
#endif