Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Catkin/Cmake includes directories as -isystem (Custom OpenCV)


I am trying to get a custom-built version of OpenCV 3.3.0 (with CUDA-support) to work with ROS Kinetic on a NVIDIA Jetson TX1. OpenCV is installed to /usr/local.

I have tried following this and this answer, but they didn't work for me.

My CMakeLists.txt-file (currently) looks like this:

cmake_minimum_required(VERSION 2.8.3)

    PATHS /usr/local

find_package(catkin REQUIRED COMPONENTS
    # ... others ...


# add_executable, add_dependencies... 


I also downloaded and built the vision_opencv-package in my workspace. When building a node, Cmake finds the correct version of OpenCV.

-- Found OpenCV: /usr/local (found suitable version "3.3.0", minimum required is "3")

However the node still includes the wrong header-files and is linked against the ROS-OpenCV-Version, as I can find out at Run-Time in my code. Looking at the build-commands with VERBOSE=1 I can see that the include-directories are part of the command, but are included with the -isystem-Flag, meaning the ROS-Includes (included with -I) will be preferred.

/usr/bin/c++ -DROSCONSOLE_BACKEND_LOG4CXX -DROS_BUILD_SHARED_LIBS=1 -DROS_PACKAGE_NAME=\"<package_name>\" -isystem /usr/local/include -isystem /usr/local/include/opencv -I<workspace>/src/vision_opencv-kinetic/cv_bridge/include -I/opt/ros/kinetic/include -I/opt/ros/kinetic/include/opencv-3.2.0-dev -I/opt/ros/kinetic/include/opencv-3.2.0-dev/opencv -I/opt/ros/kinetic/share/xmlrpcpp/cmake/../../../include/xmlrpcpp  -std=c++11 -o CMakeFiles/<node_name>.dir/src/<node_name>.cpp.o -c <workspace>/src/<package_name>/src/<node_name>.cpp

This is the linker command. I tried to shorten it a bit by using <ros_libs>=/opt/ros/kinetic/lib and <local_libs>=/usr/local/lib.

/usr/bin/c++ CMakeFiles/<node_name>.dir/src/<node_name>.cpp.o  -o <workspace>/devel/lib/<package_name>/<node_name>  -L/usr/local/cuda-8.0/lib64 -rdynamic <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ <workspace>/devel/lib/ <local_libs>/ <local_libs>/ <local_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ -lPocoFoundation -ldl <ros_libs>/ <ros_libs>/ -lpython2.7 -lboost_program_options -ltinyxml <ros_libs>/ -lboost_signals -lboost_filesystem <ros_libs>/ <ros_libs>/ <ros_libs>/ -llog4cxx -lboost_regex <ros_libs>/ <ros_libs>/ <ros_libs>/ <ros_libs>/ -lboost_system -lboost_thread -lboost_chrono -lboost_date_time -lboost_atomic -lpthread -lconsole_bridge <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ <local_libs>/ -Wl,-rpath,/usr/local/cuda-8.0/lib64:<local_libs>:<workspace>/devel/lib:<ros_libs>

The program appears to be linked against the wrong libraries since cv::cuda::getCudaEnabledDeviceCount() returns 0, which it doesn't with the right library.

So I have the following questions:

  1. Why are the include-directories included with -isystem? Can this be "turned off"?
  2. How do I link against the correct libraries?

So all in all, what changes do I have to make to my CMakeLists.txt?

Thank you!