I would like to use Snap7 ( Multi-platform Ethernet S7 PLC communication suite) to establish a communication between ROS and a Siemens S7 1500.
I encountered a linker problem - Although I can find the includes and the library .so file itself, using a custom FindLibSnap7.cmake, target_link_libraries is not linking against snap7 library. Here my approach and the outputs helping debugging:
(Note: Currently we are forced to use ROS Kinetic, so using the Snap7 Python wrapper seems like not an option cause its written in python3.)
I installed the library:
sudo add-apt-repository ppa:gijzelaar/snap7
sudo apt-get update
sudo apt-get install libsnap71 libsnap7-dev
Result:
$ ll /usr/lib/libsnap7.so
-rwxr-xr-x 1 root root 305944 Apr 24 22:18 /usr/lib/libsnap7.so*
$ ll /usr/include/snap7.h
-rw-r--r-- 1 root root 41954 Jun 2 2015 /usr/include/snap7.h
FindLibSnap7.cmake:
# find libsnap7
#
# exports:
#
# LibSNAP7_FOUND
# LibSNAP7_INCLUDE_DIRS
# LibSNAP7_LIBRARIES
#
find_package(PkgConfig REQUIRED)
# Use pkg-config to get hints about paths
#pkg_check_modules(LibSNAP7_PKGCONF REQUIRED libsnap7)
# Include dir
find_path(LibSNAP7_INCLUDE_DIR
NAMES snap7.h
PATHS ${LibSNAP7_PKGCONF_INCLUDE_DIRS}
)
find_library(
LibSNAP7_LIBRARY
NAMES snap7 libsnap7
PATHS /usr/lib
# PATH_SUFFIXES lib
# NO_DEFAULT_PATH
)
#FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibSNAP7 DEFAULT_MSG LibSNAP7_LIBRARY LibSNAP7_INCLUDE_DIR)
message("LibSNAP7_INCLUDE_DIR ${LibSNAP7_INCLUDE_DIR}")
message("LibSNAP7_LIBRARY ${LibSNAP7_LIBRARY}")
set(LibSnap7_LIBRARIES ${LibSNAP7_LIBRARY})
set(LibSnap7_INCLUDE_DIRS ${LibSNAP7_INCLUDE_DIR})
set(LibSnap7_FOUND yes)
# Set the include dir variables and the libraries and let libfind_process do the rest.
# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
#set(LibSNAP7_PROCESS_INCLUDES LibSNAP7_INCLUDE_DIR)
#set(LibSNAP7_PROCESS_LIBS LibSNAP7_LIBRARY)
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.3)
project(agv_snap7_driver)
set(CMAKE_VERBOSE_MAKEFILE ON)
## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)
##########################################################################################
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
MESSAGE( STATUS "CMAKE_MODULE_PATH: " ${CMAKE_MODULE_PATH} )
find_package(LibSnap7 REQUIRED)
include_directories(${LibSnap7_INCLUDE_DIRS})
message("LibSnap7_LIBRARIES ${LibSnap7_LIBRARIES}")
message("LibSnap7_INCLUDE_DIRS ${LibSnap7_INCLUDE_DIRS}")
##########################################################################################
## 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
nodelet
agv_utils
agv_msgs
)
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
CATKIN_DEPENDS ${THIS_PACKAGE_ROS_DEPS}
DEPENDS LibSnap7
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
include
${catkin_INCLUDE_DIRS}
${LibSnap7_INCLUDE_DIRS}
)
## Declare a C++ library
add_library(${PROJECT_NAME}
src/agv_snap7_driver_config.cpp
src/agv_snap7_driver.cpp
)
## Add cmake target dependencies of the executable
add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
## Specify libraries to link a library or executable target against
target_link_libraries( ${PROJECT_NAME} ${catkin_LIBRARIES} ${LibSnap7_LIBRARIES})
#############
## Install ##
#############
## Mark libraries for installation
install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)
## Mark cpp header files for installation
install(DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
PATTERN ".svn" EXCLUDE
)
install(FILES nodelet.xml
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
install(DIRECTORY launch/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch
FILES_MATCHING PATTERN "*.launch"
PATTERN ".svn" EXCLUDE
)
install(DIRECTORY config/
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/config
FILES_MATCHING PATTERN "*.yaml"
PATTERN ".svn" EXCLUDE
)
catkin_make output:
-- +++ processing catkin package: 'agv_snap7_driver'
-- ==> add_subdirectory(agv_base_hardware/agv_snap7_driver)
-- CMAKE_MODULE_PATH: /home/twobit/workspaces/bestvc_ws/branches/Gestamp_Amorebieta_01/base/src/agv_base_hardware/agv_snap7_driver/cmake
LibSNAP7_INCLUDE_DIR /usr/include
LibSNAP7_LIBRARY /usr/lib/libsnap7.so
LibSnap7_LIBRARIES /usr/lib/libsnap7.so
LibSnap7_INCLUDE_DIRS /usr/include
lld output
$ ldd libagv_snap7_driver.so | grep snap
libsnappy.so.1 => /usr/lib/x86_64-linux-gnu/libsnappy.so.1 (0x00007fe89c01e000)
So as you can see the includes are found, as well the library. Providing ${LibSnap7_LIBRARIES} to target_link_libraries is not linking agains libsnap7.so
After installing snap7 from source I found the example cpp's are linked correctly.
When anyone has an idea why this incorrect link is happening I would be happy for any help.
Thank you in advance!
Related
There are a lot of questions related to this, but I could not find anything that useful to me. I created a c++ script to subscribe to a camera topic. when I tried to run the script I get the following error.
receiver.cpp:1:10: fatal error: ros/ros.h: No such file or directory
1 | #include "ros/ros.h"
| ^~~~~~~~~~~
and as per I searched the internet the error is due to the CMake file. I tried various ways could not figure out why. so I have also added my CMake list file below. kindly look into it.
cmake_minimum_required(VERSION 3.0.2)
project(cv_basics)
## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)
include_directories(${OpenCV_INCLUDE_DIRS})
## 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
cv_bridge
image_transport
roscpp
rospy
sensor_msgs
std_msgs
nav_msgs
)
## Generate messages in the 'msg' folder
# add_message_files(
# FILES
# Message1.msg
# Message2.msg
# )
## Generate services in the 'srv' folder
# add_service_files(
# FILES
# Service1.srv
# Service2.srv
# )
## Generate actions in the 'action' folder
# add_action_files(
# FILES
# Action1.action
# Action2.action
# )
## Generate added messages and services with any dependencies listed here
#generate_messages(
# DEPENDENCIES
# sensor_msgs# std_msgs
# )
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES cv_basics
# CATKIN_DEPENDS cv_bridge image_transport roscpp rospy sensor_msgs std_msgs
# DEPENDS system_lib
)
include_directories(
include
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
i am using ros noetic, and ubuntu 20
You need to make sure you're building with the ros libraries in your CMakeLists.txt file. Make sure you have these lines:
add_executable(some_exe src/your_source.cpp)
target_link_libraries(some_exe ${catkin_LIBRARIES})
Of course, replace some_exe and src/your_source.cpp with their correct respective names in your package.
I am encountering a namespace issue when using ROS, OpenCV's dnn module, and CLion. The issue seems to be exclusive to the DNN module, as the other ROS and OpenCV functions work fine. While my code seems to compile and build fine, I am getting the lint error: No member named readNetFromDarknet in namespace 'cv::dnn'. The error happens everywhere I am accessing anything in the DNN module.
Defined in my header file:
cv::dnn::Net net;
yields the error No type named Net in namespace 'cv::dnn'.
Defined in my class file:
void HumanDetector::setupNetwork() {
net = cv::dnn::readNetFromDarknet(MODEL_CONFIG, MODEL_WEIGHTS);
net.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
net.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);
}
yields a similar problem.
In CLion, however, I can Ctrl+Click any of the alleged undefined members or types and see the source code for them. I suspect that it might have something to do with my CMakeLists config or IDE setup. Here is my cmake file:
cmake_minimum_required(VERSION 2.8.3)
project(followbot)
## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)
set(CATKIN_ENABLE_TESTING OFF)
set(OpenCV_LIBRARY_DIR /usr/local/lib)
set(OpenCV_DIR "/usr/local/lib")
## Find catkin macros and libraries
find_package(OpenCV 4.1.2 REQUIRED PATHS /usr/local NO_DEFAULT_PATH)
find_package(catkin REQUIRED COMPONENTS
roscpp
geometry_msgs
std_msgs
message_generation
teb_local_planner
)
add_message_files(
FILES
Point2.msg
)
generate_messages(
DEPENDENCIES
)
###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
INCLUDE_DIRS include
CATKIN_DEPENDS
roscpp
message_generation
message_runtime
std_msgs
geometry_msgs
teb_local_planner
DEPENDS OpenCV
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
include
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
add_executable(${PROJECT_NAME} src/node.cpp src/cloud.cpp src/human.cpp)
## Link the executable to the OpenCV libraries
link_directories(${OpenCV_LIBRARY_DIR})
target_link_libraries(followbot ${OpenCV_LIBRARIES} ${catkin_LIBRARIES})
I've installed osgearth package with vcpkg with following command:
vcpkg.exe install osgearth:x64-windows
Now in a CMake I want to use it.
cmake_minimum_required (VERSION 3.10.0)
project (osgmap)
add_definitions (-DOSGMAP_EXPORTS)
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/..)
find_package (Osg REQUIRED)
find_package(OsgEarth REQUIRED)
set (PROJECT_SRC
Dummy.cpp
)
add_library (${PROJECT_NAME} SHARED ${PROJECT_SRC})
target_link_libraries (${PROJECT_NAME} mapapi)
target_compile_features (${PROJECT_NAME} PUBLIC cxx_std_17)
The problem is that I cannot find osgearth package. I've tried different options.
How can I use OsgEarth installed with vcpkg in a CMake project?
The short answer is there are findosg* modules in the cmake distribution and there are not any osgEarth modules to automatically find package paths. Package is either a config or module definition locating both the libs and includes. Vcpkg does not seem to automate package definition and it relies on the modules installed with CMake. What is possible is using find_library and find_path to locate the osgearth files.
find_library(OSGEARTH_LIBRARY osgearth)
assuming you ran vcpkg integrate and use the -DCMAKE_TOOLCHAIN_FILE with cmake. All the libs that were built with vcpkg can be found but not all as packages.
Once you have properly set up the CMAKE_TOOLCHAIN_FILE you need to provide a FindOsgEarth.cmake file. You could use:
# This module defines
# OSGEARTH_LIBRARY
# OSGEARTH_FOUND, if false, do not try to link to osg
# OSGEARTH_INCLUDE_DIRS, where to find the headers
# OSGEARTH_INCLUDE_DIR, where to find the source headers
# to use this module, set variables to point to the osg build
# directory, and source directory, respectively
# OSGEARTHDIR or OSGEARTH_SOURCE_DIR: osg source directory, typically OpenSceneGraph
# OSGEARTH_DIR or OSGEARTH_BUILD_DIR: osg build directory, place in which you've
# built osg via cmake
###### headers ######
MACRO( FIND_OSGEARTH_INCLUDE THIS_OSGEARTH_INCLUDE_DIR THIS_OSGEARTH_INCLUDE_FILE )
FIND_PATH( ${THIS_OSGEARTH_INCLUDE_DIR} ${THIS_OSGEARTH_INCLUDE_FILE}
PATHS
${OSGEARTH_DIR}
$ENV{OSGEARTH_SOURCE_DIR}
$ENV{OSGEARTHDIR}
$ENV{OSGEARTH_DIR}
/usr/local/
/usr/
/sw/ # Fink
/opt/local/ # DarwinPorts
/opt/csw/ # Blastwave
/opt/
[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSGEARTH_ROOT]/
~/Library/Frameworks
/Library/Frameworks
PATH_SUFFIXES
/include/
)
ENDMACRO( FIND_OSGEARTH_INCLUDE THIS_OSGEARTH_INCLUDE_DIR THIS_OSGEARTH_INCLUDE_FILE )
FIND_OSGEARTH_INCLUDE( OSGEARTH_INCLUDE_DIR osgEarth/Version )
###### libraries ######
MACRO( FIND_OSGEARTH_LIBRARY MYLIBRARY MYLIBRARYNAME )
FIND_LIBRARY(${MYLIBRARY}
NAMES
${MYLIBRARYNAME}
PATHS
${OSGEARTH_DIR}
$ENV{OSGEARTH_BUILD_DIR}
$ENV{OSGEARTH_DIR}
$ENV{OSGEARTHDIR}
$ENV{OSG_ROOT}
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw
/opt/local
/opt/csw
/opt
[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSGEARTH_ROOT]/lib
/usr/freeware
PATH_SUFFIXES
/lib/
/lib64/
/build/lib/
/build/lib64/
/Build/lib/
/Build/lib64/
)
ENDMACRO(FIND_OSGEARTH_LIBRARY LIBRARY LIBRARYNAME)
FIND_OSGEARTH_LIBRARY( OSGEARTH_LIBRARY osgEarth)
FIND_OSGEARTH_LIBRARY( OSGEARTHFEATURES_LIBRARY osgEarthFeatures)
FIND_OSGEARTH_LIBRARY( OSGEARTHUTIL_LIBRARY osgEarthUtil )
FIND_OSGEARTH_LIBRARY( OSGEARTHQT_LIBRARY osgEarthQt )
FIND_OSGEARTH_LIBRARY( OSGEARTHSYMBOLOGY_LIBRARY osgEarthSymbology )
FIND_OSGEARTH_LIBRARY( OSGEARTHANNOTATION_LIBRARY osgEarthAnnotation )
SET( OSGEARTH_FOUND "NO" )
IF( OSGEARTH_LIBRARY AND OSGEARTH_INCLUDE_DIR )
SET( OSGEARTH_FOUND "YES" )
SET( OSGEARTH_INCLUDE_DIRS ${OSGEARTH_INCLUDE_DIR})
GET_FILENAME_COMPONENT( OSGEARTH_LIBRARIES_DIR ${OSGEARTH_LIBRARY} PATH )
ENDIF( OSGEARTH_LIBRARY AND OSGEARTH_INCLUDE_DIR )
Then add it to your CMakeModules folder and in your CMakeLists.txt:
LIST(APPEND CMAKE_MODULE_PATH "${${PROJECT_NAME}_SOURCE_DIR}/CMakeModules")
FIND_PACKAGE(OsgEarth REQUIRED)
IF(OSGEARTH_FOUND)
MESSAGE(STATUS "OsgEarth found")
ELSE()
MESSAGE(STATUS "OsgEarth NOT found")
ENDIF()
INCLUDE_DIRECTORIES(${OSGEARTH_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OSGEARTH_LIBRARY} ${OSGEARTHFEATURES_LIBRARY}
${OSGEARTHUTIL_LIBRARY} ${OSGEARTHSYMBOLOGY_LIBRARY}
${OSGEARTHANNOTATION_LIBRARY} ...)
I am trying to catkin build this ROS package https://github.com/toddhester/rl-texplore-ros-pkg but it fails to build 'rl_experiment' with the following error:
/usr/bin/ld: cannot find -lagentlib
/usr/bin/ld: cannot find -lenvlib
collect2: error: ld returned 1 exit status
I am using ROS Kinetic. The shared libraries does exist in the folders /texplore/devel/.private/rl_env/lib/ and /texplore/devel/.private/rl_agent/lib/ with symlinks at /texplore/devel/lib/
I tried the following:
(1) export /texplore/devel/lib/ to LD_LIBRARY_PATH
(2) adding symlinks to the libraries in /texplore/src/rl_experiment/src
(3) adding the library paths to target_link_libraries
target_link_libraries(experiment agentlib envlib ${catkin_LIBRARIES}
"/media/usr/texplore/devel/lib/libagentlib.so"
"/media/usr/texplore/devel/lib/libenvlib.so")
(4) set the search path for linker
SET(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,/media/usr/texplore/devel/lib/")
It didn't work. Lastly, I added the symlinks to /usr/local/lib and it worked. But I do not want the symlinks in this folder.
So the linker is simply not searching the build tree. My question is, why did catkin not add the linker path in catkin_LIBRARIES? I have built ROS packages before but can't wrap my head around why this particular package is not working.
I ran into the same issue. I made the following changes based on this post on ROS Answers and the below comment in the generic CMakeLists.txt file for the catkin_packages macro:
## LIBRARIES: libraries you create in this project that dependent projects also need
I did a few things to fix this...
Added
LIBRARIES agentlib to the catkin_packages macro in the rl_agent/CMakeLists.txt file. This makes the agentlib library available later to rl_experiment.
Added LIBRARIES envlib to the catkin_packages macro in the rl_env/CMakeLists.txt file. This makes the envlib library available later to rl_experiment.
Removed agentlib and envlib from the target_link_libraries macro in the rl_experiment/CMakeLists.txt file. These are not necessary.
Verified rl_agent and rl_env packages are listed in the find_package macro of the rl_experiment/CMakeLists.txt.
...then everything successfully compiled.
Adding snippets for further clarification...
rl_agent CMakeLists.TXT Changes (item 1 above):
...
## Declare a cpp library
# add_library(rgbd_tools
# src/${PROJECT_NAME}/
# )
add_library(agentlib
src/Agent/DiscretizationAgent.cc
src/Agent/QLearner.cc
...
src/newmat/newmatrm.cc
src/newmat/newmat9.cc
)
## Declare a cpp executable
# add_executable(rgbd_tools_node src/rgbd_tools_node.cpp)
...
rl_env CMakeLists.txt Changes (item 2 above):
...
###################################
## catkin specific configuration ##
###################################
...
catkin_package(
INCLUDE_DIRS include
LIBRARIES envlib
# CATKIN_DEPENDS roscpp rospy std_msgs
CATKIN_DEPENDS message_runtime
# DEPENDS system_lib
)
...
rl_experiment CMakeLists.txt Changes (items 3 & 4 above):
...
## 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
std_msgs
rl_common
rl_env
rl_agent
)
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
...
## Declare a cpp executable
# add_executable(rgbd_tools_node src/rgbd_tools_node.cpp)
add_executable(experiment src/rl.cc)
# target_link_libraries(experiment agentlib envlib ${catkin_LIBRARIES})
target_link_libraries(experiment ${catkin_LIBRARIES})
#add_executable(image_converter src/image_converter.cpp)
...
I'm trying to write a ROS-Node which uses OpenCV nonfree components (SURF). I have trouble compiling the package using catkin_make:
//usr/local/lib/libopencv_nonfree.so: undefined reference to `cv::ocl::integral(cv::ocl::oclMat const&, cv::ocl::oclMat&)'
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(homography_test)
## Find catkin macros and libraries
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
sensor_msgs
cv_bridge
image_transport
)
catkin_package(
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
# include_directories(include)
include_directories(
${catkin_INCLUDE_DIRS}
/usr/local/include
/usr/include
/usr/include/gstreamer-1.0
/usr/include/glib-2.0
/usr/lib/x86_64-linux-gnu/glib-2.0/include
)
## Declare a cpp executable
#add_executable(display_image src/display_image_node.cpp)
add_executable(homography src/sample.cpp)
## Add cmake target dependencies of the executable/library
## as an example, message headers may need to be generated before nodes
#add_dependencies(homography_test homography_test_generate_messages_cpp)
## Specify libraries to link a library or executable target against
target_link_libraries(
homography
${catkin_LIBRARIES}
gstreamer-1.0
gobject-2.0
glib-2.0
opencv_nonfree
opencv_calib3d
opencv_contrib
opencv_core
opencv_features2d
opencv_flann
opencv_gpu
opencv_highgui
opencv_imgproc
opencv_legacy
opencv_ml
opencv_objdetect
opencv_ocl
opencv_photo
opencv_stitching
opencv_superres
opencv_ts
opencv_video
opencv_videostab
rt
pthread
m
dl
)
link_directories(/usr/local/lib)
But if I manually compile the same code, but not as ROS-node, everything works.
It seems that the opencv_ocl library is not being linked properly. Also, you can simplify your CMakeLists.txt file a lot by using find_package to get your OpenCV configuration. Try adding those lines to your CMakeLists.txt file:
find_package(OpenCV REQUIRED core ocl)
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})
target_link_libraries(homography ${catkin_LIBRARIES} ${OpenCV_LIBRARIES} )
You need to specify which OpenCV libraries you want to include in the find_package. I listed only core and ocl since ocl seems to be what you need, but others might be needed as well.