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

asked 2017-09-29 04:06:22 -0500

CJuette gravatar image

Hello,

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)
project(<project_name>)

find_package(
    OpenCV 3 REQUIRED
    NO_MODULE
    PATHS /usr/local
    NO_DEFAULT_PATH
)

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

include_directories(
    ${OpenCV_INCLUDE_DIRS}
    ${catkin_INCLUDE_DIRS} 
)

# add_executable, add_dependencies... 

target_link_libraries(<node_name>
    ${OpenCV_LIBRARIES}
    ${catkin_LIBRARIES}
)

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>/libopencv_cudabgsegm.so.3.3.0 <local_libs>/libopencv_cudaobjdetect.so.3.3.0 <local_libs>/libopencv_cudastereo.so.3.3.0 <local_libs>/libopencv_dnn.so.3.3.0 <local_libs>/libopencv_ml.so.3.3.0 <local_libs>/libopencv_shape.so.3.3.0 <local_libs>/libopencv_stitching.so.3.3.0 <local_libs>/libopencv_superres.so.3.3.0 <local_libs>/libopencv_videostab.so.3.3.0 <ros_libs>/libcompressed_image_transport.so <ros_libs>/libopencv_calib3d3.so.3.2.0 <ros_libs>/libopencv_core3.so.3.2.0 <ros_libs>/libopencv_features2d3.so.3.2.0 <ros_libs>/libopencv_flann3.so.3.2.0 <ros_libs>/libopencv_highgui3.so.3.2.0 <ros_libs>/libopencv_imgcodecs3.so.3.2.0 <ros_libs>/libopencv_imgproc3.so.3.2.0 <ros_libs>/libopencv_ml3.so.3.2.0 <ros_libs>/libopencv_objdetect3.so.3.2.0 <ros_libs>/libopencv_photo3.so.3.2.0 <ros_libs>/libopencv_shape3.so.3.2.0 <ros_libs>/libopencv_stitching3.so.3.2.0 <ros_libs>/libopencv_superres3.so.3.2.0 <ros_libs>/libopencv_video3.so.3.2.0 <ros_libs>/libopencv_videoio3.so.3.2.0 <ros_libs>/libopencv_videostab3.so.3.2.0 <ros_libs>/libopencv_viz3.so.3.2.0 <ros_libs>/libopencv_aruco3.so.3.2.0 <ros_libs>/libopencv_bgsegm3.so.3.2.0 <ros_libs>/libopencv_bioinspired3.so.3.2.0 <ros_libs>/libopencv_ccalib3.so.3.2.0 <ros_libs>/libopencv_cvv3.so.3.2.0 <ros_libs>/libopencv_datasets3.so.3.2.0 <ros_libs>/libopencv_dpm3.so.3.2.0 ...
(more)
edit retag flag offensive close merge delete

Comments

Are we sure it's not the ROS OpenCV package setting the isystem flag? Related issue: ros/catkin#428 (but it's old, so just for reference).

gvdhoorn gravatar image gvdhoorn  ( 2017-09-29 05:14:00 -0500 )edit

I'm not sure, but I don't think so. I've tried adding Paths manually in include_directories, and I discovered something weird: When I add /usr/local it gets added to the command with the -I-flag like it should. However when I manually add /usr/local/include it gets added with -isystem.

CJuette gravatar image CJuette  ( 2017-10-04 02:33:03 -0500 )edit