Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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 <ros_libs>/libopencv_face3.so.3.2.0 <ros_libs>/libopencv_fuzzy3.so.3.2.0 <ros_libs>/libopencv_hdf3.so.3.2.0 <ros_libs>/libopencv_line_descriptor3.so.3.2.0 <ros_libs>/libopencv_optflow3.so.3.2.0 <ros_libs>/libopencv_phase_unwrapping3.so.3.2.0 <ros_libs>/libopencv_plot3.so.3.2.0 <ros_libs>/libopencv_reg3.so.3.2.0 <ros_libs>/libopencv_rgbd3.so.3.2.0 <ros_libs>/libopencv_saliency3.so.3.2.0 <ros_libs>/libopencv_stereo3.so.3.2.0 <ros_libs>/libopencv_structured_light3.so.3.2.0 <ros_libs>/libopencv_surface_matching3.so.3.2.0 <ros_libs>/libopencv_text3.so.3.2.0 <ros_libs>/libopencv_xfeatures2d3.so.3.2.0 <ros_libs>/libopencv_ximgproc3.so.3.2.0 <ros_libs>/libopencv_xobjdetect3.so.3.2.0 <ros_libs>/libopencv_xphoto3.so.3.2.0 <ros_libs>/libdynamic_reconfigure_config_init_mutex.so <workspace>/devel/lib/libcv_bridge.so <local_libs>/libopencv_core.so.3.3.0 <local_libs>/libopencv_imgproc.so.3.3.0 <local_libs>/libopencv_imgcodecs.so.3.3.0 <ros_libs>/libimage_transport.so <ros_libs>/libmessage_filters.so <ros_libs>/libclass_loader.so -lPocoFoundation -ldl <ros_libs>/libroslib.so <ros_libs>/librospack.so -lpython2.7 -lboost_program_options -ltinyxml <ros_libs>/libroscpp.so -lboost_signals -lboost_filesystem <ros_libs>/librosconsole.so <ros_libs>/librosconsole_log4cxx.so <ros_libs>/librosconsole_backend_interface.so -llog4cxx -lboost_regex <ros_libs>/libxmlrpcpp.so <ros_libs>/libroscpp_serialization.so <ros_libs>/librostime.so <ros_libs>/libcpp_common.so -lboost_system -lboost_thread -lboost_chrono -lboost_date_time -lboost_atomic -lpthread -lconsole_bridge <local_libs>/libopencv_cudafeatures2d.so.3.3.0 <local_libs>/libopencv_cudacodec.so.3.3.0 <local_libs>/libopencv_cudaoptflow.so.3.3.0 <local_libs>/libopencv_cudalegacy.so.3.3.0 <local_libs>/libopencv_calib3d.so.3.3.0 <local_libs>/libopencv_cudawarping.so.3.3.0 <local_libs>/libopencv_features2d.so.3.3.0 <local_libs>/libopencv_flann.so.3.3.0 <local_libs>/libopencv_highgui.so.3.3.0 <local_libs>/libopencv_objdetect.so.3.3.0 <local_libs>/libopencv_photo.so.3.3.0 <local_libs>/libopencv_cudaimgproc.so.3.3.0 <local_libs>/libopencv_cudafilters.so.3.3.0 <local_libs>/libopencv_cudaarithm.so.3.3.0 <local_libs>/libopencv_video.so.3.3.0 <local_libs>/libopencv_videoio.so.3.3.0 <local_libs>/libopencv_imgcodecs.so.3.3.0 <local_libs>/libopencv_imgproc.so.3.3.0 <local_libs>/libopencv_core.so.3.3.0 <local_libs>/libopencv_cudev.so.3.3.0 -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!