1. 程式人生 > >catkin_make時報錯找不到custom include custom.h

catkin_make時報錯找不到custom include custom.h

folder fatal pre efi minimum 沒有 head post reat

參考:
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

catkin_make時報錯找不到custom include custom.h