Search code examples
c++cmakemakefileroscatkin

How to include library headers in CMakeLists


I'm having trouble getting CMake and Make to find external header files I need to compile my code.

My code has is trying to use a header provided by the external aruco library

#include <aruco.h>

And when I try to compile I get

/home/ncr/ncr_ws/src/aruco_ros/src/aruco_ros_node.cpp:21:19: fatal error: aruco.h: No such file or directory
#include <aruco.h>
                 ^
compilation terminated.

My CMakeLists.txt has:

cmake_minimum_required(VERSION 2.8.3)
project(aruco_ros)

set(CMAKE_MODULE_PATH /usr/local/lib/cmake)
message( STATUS "CMAKE_MODULE_PATH: " ${CMAKE_MODULE_PATH})
find_package(OpenCV REQUIRED)
find_package(aruco REQUIRED)
...
include_directories(
    ${OpenCV_INCLUDE_DIRS}
    ${aruco_INCLUDE_DIRS}
)
message(STATUS "OpenCV_INCLUDE_DIRS: " ${OpenCV_INCLUDE_DIRS})
message(STATUS "aruco_INCLUDE_DIRS: " ${aruco_INCLUDE_DIRS})

The Findaruco.cmake file is in /usr/local/lib/cmake/Findaruco.cmake

The Findaruco.cmake file sets the aruco_INCLUDE_DIRS variable as /usr/local/include and the include file aruco.h is in /usr/local/include/aruco. Does make not search subdirectories? Most of the opencv headers are in /usr/local/include/opencv2 but the OpenCV_INCLUDE_DIRS only declares /usr/local/include and yet all opencv the headers are found without any problem.


Solution

  • As James Adkison said, I needed to properly reference the header files. Looking at the other opencv include files, I start them all off with #include <opencv2/[blah]>, which explains why those work as well.