0
$\begingroup$

Rosanswers logo

I've built OpenCV 2.4.7 with CUDA support and tried to link it to my package. When I run my node, I get this error error.

OpenCV Error: No GPU support (The library is compiled without CUDA support) in mallocPitch, file /tmp/buildd/ros-groovy-opencv2-2.4.6-1precise-20131020-2316/modules/core/src/gpumat.cpp, line 879 terminate called after throwing an instance of 'cv::Exception' what():  /tmp/buildd/ros-groovy-opencv2-2.4.6-1precise-20131020-2316/modules/core/src/gpumat.cpp:879: error: (-216) The library is compiled without CUDA support in function mallocPitch

When I compile, I get the following errors:

runtime library [libopencv_videostab.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib
runtime library [libopencv_video.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib
runtime library [libopencv_superres.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib
runtime library [libopencv_stitching.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib
runtime library [libopencv_photo.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib
runtime library [libopencv_objdetect.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib
runtime library [libopencv_nonfree.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib
runtime library [libopencv_ml.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib
runtime library [libopencv_legacy.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib
runtime library [libopencv_imgproc.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib
runtime library [libopencv_highgui.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib
runtime library [libopencv_gpu.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib
runtime library [libopencv_flann.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib
runtime library [libopencv_features2d.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib
runtime library [libopencv_core.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib
runtime library [libopencv_contrib.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib
runtime library [libopencv_calib3d.so.2.4] in /usr/local/lib may be hidden by files in:
  /opt/ros/groovy/lib

My CMakeLists.txt file is as follows:

cmake_minimum_required(VERSION 2.8.3)
project(objectdetect)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED 
    COMPONENTS 
    roscpp
    message_generation
    cv_bridge
    sensor_msgs
    std_msgs
    )
#Find opencv packages 
find_package(OpenCV 2.4.7 REQUIRED)

#Find the CUDA packages
find_package(CUDA REQUIRED)
#Fix for error messages()
set(config )

catkin_package(
   CATKIN_DEPENDS roscpp
   cv_bridge
)
 
include_directories(${OpenCV_INCLUDE_DIRS})

cuda_add_library(objectdetect.a objectdetect.cu rslvr.cu OPTIONS -G)
cuda_add_cufft_to_target(objectdetect.a)

add_executable(objectdetect_node objectdetect_node.cpp)

target_link_libraries(objectdetect_node
    objectdetect.a
    ${catkin_LIBRARIES}
    ${OpenCV_LIBS}
    )

Can anybody explain why this is linking to the ROS OpenCV package and not my /usr/local version? Also, how do I fix it?


Originally posted by DiJuMx on ROS Answers with karma: 1 on 2014-01-27

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You have a problem similar to this one: http://answers.ros.org/question/32284/cmakelist-find_package-opencv-svn or even this one http://answers.ros.org/question/47249/problem-with-using-opencv_gpu-inside-ros

Try to export OpenCV_DIR to your local installation of OpenCV. More details are available in the answer to the first similar question and in the documentation of find_package.

Having both OpenCV versions installed can lead to clashes between libraries. You can try to update your LD_LIBRARY_PATH/PKG_CONFIG_PATH (if the scripts rely on pkg-config) accordingly, i.e. something like:

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

You may also need to set CMAKE_LIBRARY_PATH="/usr/local/lib" for CMake.

If you just need OpenCV with CUDA support for ROS, you can recompile the package with CUDA support activated.


Originally posted by bchr with karma: 596 on 2014-01-27

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by DiJuMx on 2014-01-27:
Unfortunately exporting CMAKE_PREFIX_PATH and OpenCV_DIR seems to fix the compile errors but not the runtime errors. It's still looking for groovy libs.

Comment by bchr on 2014-01-27:
For the runtime error, add the directory to LD_LIBRARY_PATH before the ROS directory. It basically stops at the first correct library it finds (in your case, the one in /opt/ros/groovy/lib must appear first in LD_LIBRARY_PATH).

Comment by DiJuMx on 2014-01-27:
I have /usr/local/lib first in LD_LIBRARY_PATH and it's still giving me runtime errors.

Comment by bchr on 2014-01-27:
Is the only reason for you to use this second OpenCV the CUDA support? It may be smarter to just use the ROS one that you recompile with CUDA support (-DWITH_CUDA=ON).

Comment by DiJuMx on 2014-01-27:
That's right. However, I consider rebuilding ROS a last resort as I'm on a University Computer. I'm more concerned with why catkin is linking to ROS libraries rather than the libraries specified.

Comment by bchr on 2014-01-27:
Can you try with: export CMAKE_PREFIX_PATH=/usr/local:$CMAKE_PREFIX_PATH ? (cf. second answer I linked)

Comment by DiJuMx on 2014-01-27:
It's already in my .bashrc ... do you want it before or after the Lines where I source my setup.bash files?

Comment by bchr on 2014-01-27:
The problem with catkin/CMake is that it tends to hide errors when trying to link with other libraries. I had a lot of problems when linking with Ogre 1.8 on a system with Ogre 1.9 installed. CMAKE_LIBRARY_PATH + PKG_CONFIG_PATH + LD_LIBRARY_PATH seemed to do the trick for all possible scenarios.

Comment by DiJuMx on 2014-01-27:
The linking errors have returned again. I think it's because I removed my build directory. It's also happening with another package in the same workspace, which does need opencv but not the CUDA enabled version...

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.