ROS hydro opencv2 linking error during 'catkin_make' - c++

I have little problem with my ROS hydro distro. I need to use it for one project so can't change to Indiko.
Problem is that I have used catkin_create_pkg packname opencv2 ... for creating my project package. But when I try to invoke catkin_make I get following errors:
CMake Error at /opt/ros/hydro/share/catkin/cmake/catkinConfig.cmake:75
(find_package): Could not find a package configuration file provided
by "opencv2" with any of the following names:
opencv2Config.cmake
opencv2-config.cmake
Add the installation prefix of "opencv2" to CMAKE_PREFIX_PATH or set
"opencv2_DIR" to a directory containing one of the above files. If
"opencv2" provides a separate development package or SDK, be sure it
has been installed.
I know that opencv2 is installed, because I can find it with rospack find opencv2 and I can use it in other projects not related to ROS.
I have following lines in CMakeLists.txt and package.xml
CMakeLists.txt:
find_package(catkin REQUIRED COMPONENTS opencv2)
include_directories(
${catkin_INCLUDE_DIRS}
${opencv2_INCLUDE_DIRS} )
target_link_libraries(BasicObstDetect_node
${catkin_LIBRARIES}
${opencv2_LIBRARIES} )
package.xml:
<build_depend>opencv2</build_depend>
<run_depend>opencv2</run_depend>
I have tried to use OpenCV instead of opencv2 but that didn't make any difference. Any advices?

I'm not sure, but this might work: edit your CMakeLists to add
find_package(OpenCV)
include_directories(${OpenCV_INCLUDE_DIRS})
and
target_link_libraries(follower ${OpenCV_LIBRARIES})

Related

CMake is having problems to compile a project which uses OpenCV

I'm on Linux Mint 19.1 Tessa.
I followed the instructions described here to install OpenCV. Now I have it installed at the directory "/home/dell/opencv".
I tryed to run the example project located at "/home/dell/opencv/samples/cpp/example_cmake/" by running the command "cmake ." on terminal and I got the following error:
CMake Error at CMakeLists.txt:14 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/home/dell/opencv/samples/cpp/example_cmake/CMakeFiles/CMakeOutput.log".
The "CMakeLists.txt" file contains the following:
# cmake needs this line
cmake_minimum_required(VERSION 3.1)
# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# Define project name
project(opencv_example_project)
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV REQUIRED)
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " config: ${OpenCV_DIR}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
# Declare the executable target built from your sources
add_executable(opencv_example example.cpp)
# Link your application with OpenCV libraries
target_link_libraries(opencv_example LINK_PRIVATE ${OpenCV_LIBS})
I've searched a lot through the internet and it seems to be a common problem. However, I still didn't manage to solve it by following the intructions that I've found.
One thing that I notice when going through the OpenCV folder is that the version that I have (which I think it's the most recent one) indeed doesn't contain any "OpenCVConfig.cmake" file, as you can see here. However, an oldest version of OpenCV that I found on github have this file, as you can see here.
So, maybe some configuration is set to this oldest version and it's causing conflict? How to change that and get it working for the newest version? I think it must be something simple to solve but I'm quite newbie.
Thanks in advance.
CMake writes you what to do:
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files.
Another option - please, read comments in the file CMakeLists.txt that you've pasted, once more.
They say:
you may need to set OpenCV_DIR variable
to the absolute path to the directory containing OpenCVConfig.cmake
Another issue - in-source build, performed with passing dot to cmake. It is better to create separate directory for build files.
Building this way allows you easily adding your build directory to .gitignore and not polluting your source code repository with compiled binaries. Also, if something goes wrong, you can just remove that build directory and start again from scratch. That is much easier than messing with files one by one.
So, you need to call CMake like following
mkdir build
cd build
OpenCV_DIR=/home/dell/opencv cmake ..
or
mkdir build
cd build
cmake .. -DCMAKE_PREFIX_PATH=/home/dell/opencv
or the following also should do the trick
mkdir build
cd build
cmake .. -DOpenCV_DIR=/home/dell/opencv
Update your OpenCV search directory path as below,
find_package(OpenCV 3.4 REQUIRED PATHS "/usr/local/opencv/" NO_DEFAULT_PATH)

Using OpenCV on windows and Clion

So I'm trying to use OpenCV on windows (my ubunut is broken) and I can't configure my Clion to compile my openCV code.
first; i'm completely new to OpenCV so this question might be an easy one but I did all I could to find the problem to no avail.
I used MinGW and Clion and my codes run with no problem if I don't use OpenCv which indicates there's no problem with MinGW installation.
I downloaded OpenCv files and extracted them, then added them to System path.
after that I configured my Cmakelists.txt (my first time modifying it, so I was an amateur) like this.
After that I got this error:
Error:By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided
by "OpenCV", but CMake did not find one. Could not find a package
configuration file provided by "OpenCV" with any of the following
names: OpenCVConfig.cmake opencv-config.cmake Add the installation
prefix of "OpenCV" to CMAKE_PREFIX_PATH or set "OpenCV_DIR" to a
directory containing one of the above files. If "OpenCV" provides a
separate development package or SDK, be sure it has been installed.
I know I'm doing something wrong or missing a step but I can't figure out why. is there any guide or tutorial for my scenario or can anyone point me towards a correct direction?
thanks in advance and any help appreciated.
I managed to make those errors go away with changing my
CMakeLists.txt to:
cmake_minimum_required(VERSION 3.5)
project(something)
set(OpenCV_DIR "E:/Programs/programming/opencv/build2") find_package( OpenCV REQUIRED )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp) add_executable(something ${SOURCE_FILES})
add_executable( {SOURCE_FILES} DisplayImage ) target_link_libraries( ${OpenCV_LIBS} DisplayImage )
and building the libraries on my own by minGW and Cmake.

CMake file cannot locate Qt charts module

I'm trying to start writing my Qt project inside JetBrains' Clion but I need to link some libraries in my Cmake file first. There's no problem when trying to find packages like Qt5Core, Qt5Widgets, Qt5Gui but when it come to finding Qt5Charts an error is thrown:
By not providing "FindQt5Charts.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file
provided by "Qt5Charts", but CMake did not find one.
Could not find a package configuration file provided by "Qt5Charts"
with any of the following names:
Qt5ChartsConfig.cmake
qt5charts-config.cmake
Add the installation prefix of "Qt5Charts" to CMAKE_PREFIX_PATH or
set "Qt5Charts_DIR" to a directory containing one of the above
files. If "Qt5Charts" provides a separate development package or
SDK, be sure it has been installed.
This is my CMake file right now.
All packages are installed via the Qt's Linux(ubuntu) maintanence tool.
Any ideas how to help Cmake find the Charts module ?
Using the following and see if it helps:
sudo apt install libqt5charts5-dev
Src: https://stackoverflow.com/a/46765025
Typically when including Qt5 in a project I use the follow basic script for CMake, though I should note I haven't tested this on Linux.
cmake_minimum_required(VERSION 3.10.0 FATAL_ERROR)
project(<YOUR_PROJECT_NAME>)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Charts)
# set your project sources and headers
set(project_sources src/blah.cpp)
set(project_headers include/headers/blah.h)
# wrap your qt based classes with qmoc
qt5_wrap_cpp(project_source_moc ${project_headers})
# add your build target
add_executable(${PROJECT_NAME} ${project_sources} ${project_headers} ${project_source_moc})
# link to Qt5
target_link_libraries(${PROJECT_NAME}
PUBLIC
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::Charts)
# require C++ 14
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14)
When configuring your project via cmake, you just need to pass in the path to you qt5 installation directory (cmake variable name is Qt5_DIR) that contains the Qt5Config.cmake file and then cmake should be able to find the rest of the components that you request.
Also double check that Qt5Charts was installed, not sure if it's installed by default.
Maybe try this?
sudo apt install libqt5charts5-dev

Include cpp-netlib with CLion and Make on macOS

I'm very new to CLion, CMake and macOS at all so I need a little bit of help while trying to include cppnetlib into my CLion project.
I started out with creating an new CLion project which gave me a new CMakeLists.txt which I edited so that it would include boost as well:
CMAKE_MINIMUM_REQUIRED(VERSION 3.7)
PROJECT(myapp)
SET(CMAKE_CXX_STANDARD 11)
SET(SOURCE_FILES main.cpp)
ADD_EXECUTABLE(myapp ${SOURCE_FILES})
FIND_PACKAGE(Boost 1.63.0 REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(dxcheck ${Boost_LIBRARIES})
I've installed boost through homebrew, but I did not find a package for cppnetlib with homebrew so I downloaded cppnetlib and placed it in /usr/local/Cellar/cpp-netlib. Now, when I follow the tutorial on their page and put
set (CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} /usr/local/Cellar/cpp-netlib)
find_package (cppnetlib 0.12.0 REQUIRED)
include_directories (${CPPNETLIB_INCLUDE_DIRS})
target_link_libraries (myapp ${CPPNETLIB_LIBRARIES})
into the CMakeLists.txt, I get the following output:
-- Boost version: 1.63.0
CMake Error at CMakeLists.txt:14 (find_package):
By not providing "Findcppnetlib.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"cppnetlib", but CMake did not find one.
Could not find a package configuration file provided by "cppnetlib"
(requested version 0.11.0) with any of the following names:
cppnetlibConfig.cmake
cppnetlib-config.cmake
Add the installation prefix of "cppnetlib" to CMAKE_PREFIX_PATH or set
"cppnetlib_DIR" to a directory containing one of the above files. If
"cppnetlib" provides a separate development package or SDK, be sure it has
been installed.
I've already done some research about finding packages but all I could achieve was that I was able to include cppnetlib by manually adding the include path to the CMakeLists.txt but then I got an error saying that the compiler could not find the headers which are located inside the "deps" folder in cpp-netlib.
I know want to know how to include a package like cppnetlib properly into my CLion project using CMake. I am using CLion 2017.1, macOS Sierra and I think CLion is using CMake 3.7.

How to link shared object in cmake?

How can I link shared object to my own code in cmake ?
I'd like to link OpenCV, I mean libopencv_***.so.3.1 or something like that to my own software package.
In that case, I believe the following lines are the answer of this question.
...
find_package(OpenCV 3.1)
include_directories(${OpenCV_INCLUDE_DIRS})
link_directories(${OpenCV_LIBRARY_DIRS})
...
target_link_libraries(my_node ${OpenCV_LIBRARIES})
But, here's this problem.
I've installed OpenCV 2.4.8 under /usr/include and /usr/lib/x86_64-linux-gnu before, and now I'd like to use OpenCV 3.1.0 installed in local directory "~/Libs/opencv" from code.
So when compiling the codes, OpenCV 2.4.8 takes priority and is used.
In this case, how should I describe CMakeLists.txt ?
Currently I'm writing as the follow.
...
set(CMAKE_PREFIX_PATH ${HOME}/Libs/opencv)
include(${HOME}/Libs/opencv/share/OpenCV/OpenCVConfig.cmake)
find_package(OpenCV 3.1)
set(OpenCV_INCLUDE_DIRS ${HOME}/Libs/opencv/include)
include_directories(${OpenCV_INCLUDE_DIRS)
set(OpenCV_LIBRARY_DIRS ${HOME}/Libs/opencv/lib)
link_directories(${OpenCV_LIBRARY_DIRS})
...
The above CMakeLists.txt kind of helped me.
If executable file is copied to the same directory where libopencv_***.so.3.1 is, the above CMakeLists.txt works.
Otherwise, "make" fails.
But I'd like to make it independent on the directory which contains executable file.
How should I do for this problem ?
Thanks in advance.
See cmake's doc of find_library.
Some predefined paths are used to search for libs. (Platform dependent). It is possible to disable this by options.
Try
find_package(OpenCV 3.1 PATHS ~/Libs/opencv NO_DEFAULT_PATH NO_SYSTEM_ENVIRONMENT_PATH)