Catkin_make doesn't recognize $(OpenCV_LIBRARIES)
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 $(OpenCVLIBRARIES) wihtin that CMakeLists.txt
. Same thing if I use `imagetransportinstead of
cv_bridge`.
This still doesn't fully answer my question. Where are these variables defined?
Asked by acajic on 2016-05-21 08:01:39 UTC
Answers
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?
Asked by ahendrix on 2016-05-22 15:49:21 UTC
Comments
He seems to already have that in his CMakeLists.txt
though (4th line)
Asked by spmaniato on 2016-05-22 15:51:38 UTC
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.
Asked by acajic on 2016-05-23 05:03:35 UTC
Comments