Ask Your Question
0

Catkin_make doesn't recognize $(OpenCV_LIBRARIES)

asked 2016-05-21 08:01:39 -0500

acajic gravatar image

updated 2016-05-21 08:50:19 -0500

In my catkin workspace and in my catkin package I have CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(vp)

find_package(catkin REQUIRED)
find_package(OpenCV REQUIRED)

catkin_package()

include_directories(include
    $(catkin_INCLUDE_DIRS)
)

add_executable(vp_node src/vp_node.cpp)

target_link_libraries(vp_node
    ${catkin_LIBRARIES}
    ${OpenCV_LIBRARIES}
)

On catkin_make, the output is:

####
#### Running command: "make cmake_check_build_system" in "/home/andrija/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/andrija/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/andrija/catkin_ws/devel;/opt/ros/jade
-- This workspace overlays: /home/andrija/catkin_ws/devel;/opt/ros/jade
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/andrija/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.6.16
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - vp
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'vp'
-- ==> add_subdirectory(vp)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/andrija/catkin_ws/build
####
#### Running command: "make -j2 -l2" in "/home/andrija/catkin_ws/build"
####
Scanning dependencies of target vp_node
[100%] Building CXX object vp/CMakeFiles/vp_node.dir/src/vp_node.cpp.o
Linking CXX executable /home/andrija/catkin_ws/devel/lib/vp/vp_node
c++: error: $(OpenCV_LIBRARIES): No such file or directory
make[2]: *** [/home/andrija/catkin_ws/devel/lib/vp/vp_node] Error 1
make[1]: *** [vp/CMakeFiles/vp_node.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j2 -l2" failed

If, however, I choose not to use variable OpenCV_LIBRARIES, but instead just use the specific libraries I need for my code, like this:

target_link_libraries(vp_node
    ${catkin_LIBRARIES}
    opencv_core opencv_highgui opencv_videoio opencv_imgcodecs
)

Then code builds and runs successfully. Where and when is this variable OpenCV_LIBRARIES being set?

I have built OpenCV from source and installed ros using apt-get.

EDIT #1

If I change my CMakeLists.txt and transform the line:

find_package(catkin REQUIRED)

into

find_package(catkin REQUIRED cv_bridge)

then I can freely use $(OpenCV_LIBRARIES) wihtin that CMakeLists.txt. Same thing if I use image_transport instead of cv_bridge.

This still doesn't fully answer my question. Where are these variables defined?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-05-22 15:49:21 -0500

ahendrix gravatar image

updated 2016-05-22 16:16:56 -0500

In CMake, the find_package() command is used to make information about other packages available to your build process.

By convention, most packages provide pacakge_INCLUDE_DIRS, package_LIBRARIES, and usually a few other variables.

So, if you want to use OpenCV and the OpenCV_INCLUDE_DIRS and OpenCV_LIBRARIES variables in your project, you need to do:

 find_package(OpenCV REQUIRED)

(And yes, cmake is slightly crazy for having a function which creates variables as a side-effect)

UPDATE:

The example and your sample both use braces for the variable name: ${OpenCV_LIBRARIES} (correct), but the error message you posted uses parentheses: $(OpenCV_LIBRARIES) (incorrect). Is it possible that this is typo in a part of your CMakeLists.txt that you didn't post?

edit flag offensive delete link more

Comments

1

He seems to already have that in his CMakeLists.txt though (4th line)

spmaniato gravatar image spmaniato  ( 2016-05-22 15:51:38 -0500 )edit

spmaniato is right, I already have that. Regarding the brackets-parentheses, I think that was just error log formatting, I am pretty sure I copy/pasted the CMakeLists.txt.

I ended up uninstalling both ROS and OpenCV... Installing OpenCV 2.4 and then ROS again, and everything worked.

acajic gravatar image acajic  ( 2016-05-23 05:03:35 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-05-21 08:01:39 -0500

Seen: 1,135 times

Last updated: May 22 '16