/usr/bin/ld: cannot find -lopencv_nonfree - c++

I installed OpenCV 4.1 on Ubuntu 18.04 LTS. The problem is when I compile my project's CMake file, the output is:
/usr/bin/ld: cannot find -lopencv_nonfree
collect2: error: ld returned 1 exit status
CMakeFiles/river_flow_velocity_estimation.dir/build.make:274: recipe for target 'river_flow_velocity_estimation' failed
make[2]: *** [river_flow_velocity_estimation] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/river_flow_velocity_estimation.dir/all' failed
make[1]: *** [CMakeFiles/river_flow_velocity_estimation.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
My CMake flags when I compile OpenCV are:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D BUILD_EXAMPLES=ON -D OPENCV_GENERATE_PKGCONFIG=YES -D OPENCV_ENABLE_NONFREE=ON -D WITH_OPENMP=ON -D WITH_OPENCL=ON -D INSTALL_CREATE_DISTRIB=ON -DBUILD_opencv_world=OFF -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..
Can someone help me?

Related

macOS Monterey --> fatal error: 'opencv2/videoio.hpp' file not found

I am trying to build opencv on macOS for a CPP capstone project but when I try to compile like so:
cmake -D CMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF -D BUILD_opencv_objdetect=OFF -D BUILD_opencv_video=OFF -D BUILD_opencv_videoio=OFF -D BUILD_opencv_features2d=OFF -D BUILD_opencv_flann=OFF -D BUILD_opencv_highgui=OFF -D BUILD_opencv_ml=OFF -D BUILD_opencv_photo=OFF -D BUILD_opencv_python=OFF -D BUILD_opencv_shape=OFF -D BUILD_opencv_stitching=OFF -D BUILD_opencv_superres=OFF -D BUILD_opencv_ts=OFF -D BUILD_opencv_videostab=OFF ..
make -j8
I am getting the following error:
[ 98%] Built target opencv_model_diagnostics
make[2]: *** No rule to make target `zlib', needed by `lib/python3/cv2.cpython-39-darwin.so'. Stop.
make[2]: *** Waiting for unfinished jobs....
[ 98%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o
In file included from /Users/username/Projects/opencv/opencv/modules/python/src2/cv2.cpp:11:
In file included from /Users/username/Projects/opencv/opencv/build/modules/python_bindings_generator/pyopencv_generated_include.h:50:
/Users/username/Projects/opencv/opencv/modules/gapi/include/opencv2/gapi/streaming/cap.hpp:26:10: fatal error: 'opencv2/videoio.hpp' file not found
#include "opencv2/videoio.hpp"
^~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o] Error 1
make[1]: *** [modules/python3/CMakeFiles/opencv_python3.dir/all] Error 2
make: *** [all] Error 2
I did follow at first the instruction from opencv but make step fails at:
[ 36%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/int8layers/layers_common.avx512_skx.cpp.o
[ 36%] Linking CXX shared library ../../lib/libopencv_dnn.dylib
[ 36%] Built target opencv_dnn
make: *** [all] Error 2
Any help is highly appreciated.

Fix the build issue when using 'make' command when installing OSRM

I am setting up a OSRM server locally on a EC2 instance which is running Ubuntu 18.04.
I have followed the following steps to install OSRM:-
sudo apt update
sudo apt install -y git \
cmake \
build-essential \
jq \
liblua5.2-dev \
libboost-all-dev \
libprotobuf-dev \
libtbb-dev \
libstxxl-dev \
libbz2-dev
git clone https://github.com/Project-OSRM/osrm-backend.git
cd osrm-backend/
mkdir build
cd build/
cmake ..
make /* fails here */
On executing this in the given sequence, I get this error
[ 8%] Built target UTIL
[ 10%] Built target MICROTAR
[ 12%] Linking CXX executable osrm-components
CMakeFiles/osrm-components.dir/src/tools/components.cpp.o:components.cpp:function main: error: undefined reference to 'boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
collect2: error: ld returned 1 exit status
CMakeFiles/osrm-components.dir/build.make:132: recipe for target 'osrm-components' failed
make[2]: *** [osrm-components] Error 1
CMakeFiles/Makefile2:100: recipe for target 'CMakeFiles/osrm-components.dir/all' failed
make[1]: *** [CMakeFiles/osrm-components.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2
Thanks in advance
Reinstalling everything in the same manner after deleting every related file and folder worked for me.

OpenCV linking error

The same error first occured in the middle of the build when linking another shared library. Then I've added BUILD_SHARED_LIBS=OFF so now it occurs at the very end only. The last two options were also added in hope of fixing it. Using LinuxMint 17.
[ 99%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/deblurring.cpp.o
[ 99%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/motion_stabilizing.cpp.o
Linking CXX static library ../../lib/libopencv_videostab.a
[ 99%] Built target opencv_videostab
[ 99%] Generating pyopencv_generated_include.h, pyopencv_generated_funcs.h, pyopencv_generated_types.h, pyopencv_generated_type_reg.h, pyopencv_generated_ns_reg.h
Scanning dependencies of target opencv_python2
[ 99%] Building CXX object modules/python2/CMakeFiles/opencv_python2.dir/__/src2/cv2.cpp.o
Linking CXX shared module ../../lib/cv2.so
/usr/bin/ld: //usr/local/lib/libavformat.a(allformats.o): relocation R_X86_64_32 against `ff_a64_muxer' can not be used when making a shared object; recompile with -fPIC
//usr/local/lib/libavformat.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [lib/cv2.so] Error 1
make[1]: *** [modules/python2/CMakeFiles/opencv_python2.dir/all] Error 2
make: *** [all] Error 2
Command:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D PYTHON_EXECUTABLE=/home/serj/work/beautytorch/venv/bin/python \
-D BUILD_EXAMPLES=OFF \
-D BUILD_SHARED_LIBS=OFF \
-D CMAKE_CXX_FLAGS=-fPIC \
-D WITH_IPP=OFF \
..
It is ffmpeg which should have been compiled with -fPIC. enter link description here I had ffmpeg compiled from sources. After deinstallation, opencv links fine.

OpenCV make on Ubuntu with opencv_contrib fails due to opencv_xphoto

I'm trying to build OpenCV on Ubuntu 15.10 with opencv_contrib (to use the nonfree modules). I did the following:
cmake -D CMAKE_BUILD_TYPE=RELEASE -DOPENCV_EXTRA_MODULES_PATH=/home/myname/Downloads/opencv_contrib-master/modules -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=OFF -D WITH_OPENGL=ON -D BUILD_opencv_ximgproc=ON ..
but I tried also with
BUILD_opencv_ximgproc=OFF
CMake goes well but it fails during the make step:
CMakeFiles/Makefile2:8403: recipe for target 'modules/xphoto/CMakeFiles/opencv_xphoto.dir/all' failed
make[1]: *** [modules/xphoto/CMakeFiles/opencv_xphoto.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
and then:
Makefile:136: recipe for target 'all' failed
make: *** [all] Error 2
Do you have any suggestions?
Thanks.
I solved it by deleting and re-downloading both opencv and opencv_contrib. Then I built everything again:
git clone https://github.com/Itseez/opencv.git
git clone https://github.com/Itseez/opencv_contrib.git
cd opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -DOPENCV_EXTRA_MODULES_PATH=/home/myname/Downloads/opencv_contrib/modules -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=OFF -D WITH_OPENGL=ON -D BUILD_opencv_ximgproc=ON ..
make -j7
sudo make install

building opencv fail on Qiana

I encountered the problem during compiling OpenCV. Error message said that I don't have Eigen. However, I do have one in my /usr/local/include directory. Also, I ran CMake with option below.
CMake:
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D CUDA_GENERATION=Auto USE_EIGEN=/usr/local/include/Eigen ..
Compiling OpenCV(by make):
[ 75%] Building CXX object modules/contrib/CMakeFiles/opencv_contrib.dir/src/rgbdodometry.cpp.o
/home/gom7745/IR/opencv-2.4.11/modules/contrib/src/rgbdodometry.cpp:65:47: fatal error: unsupported/Eigen/MatrixFunctions: No such file or directory
# include <unsupported/Eigen/MatrixFunctions>
^
compilation terminated.
make[2]: *** [modules/contrib/CMakeFiles/opencv_contrib.dir/src/rgbdodometry.cpp.o] Error 1
make[1]: *** [modules/contrib/CMakeFiles/opencv_contrib.dir/all] Error 2
make: *** [all] Error 2
Does anyone have any idea about this? Thanks!!
Building it with -DWITH_EIGEN=OFF solved the issue for me.
here cmake is unable to find unsupported/Eigen/MatrixFunctions. First find where Eigen is installed, in my case it was located at /usr/local/include/eigen3. Now locate your rgbdodometry.cpp file, in my case it was in /opencv_contrib/modules/rgbd/src. Open the cpp file and modify the previous line with something like
"/usr/local/include/eigen3/unsupported/Eigen/MatrixFunctions"