OpenCV libraries missing - c++

I'm failing to build a project in c++ where OpenCV is used. Here is what I got:
/usr/bin/ld: cannot find -leigen
/usr/bin/ld: cannot find -lhighgui
/usr/bin/ld: cannot find -lcore
/usr/bin/ld: cannot find -leigen
/usr/bin/ld: cannot find -lhighgui
/usr/bin/ld: cannot find -lcore
But there are only libraries like "-lopencv_core" available nowadays.
Is there any options how to fix this?
I'm using Ubuntu.

How did you install your distribution of OpenCV. The typical way of installing OpenCV is to download git repo and build it yourself.

Related

"/usr/bin/ld: cannot find -llibopencv_calib3d" when compiling an opencv project in Ubuntu 20.04

I have installed opencv in Ubuntu 20.04 following the instructions in OpenCV Installation in Linux. As per the instructions, sudo make install copies all the .so files to /usr/local/lib.
However, when compiling a program, using the command g++ --std c++17 -g opencv/Basic.cpp -o output -I/usr/local/include/opencv4 -L/usr/local/lib/ -llibopencv_calib3d -llibopencv_core -llibopencv_dnn -llibopencv_features2d -llibopencv_flann -llibopencv_highgui -llibopencv_imgcodecs -llibopencv_imgproc -llibopencv_ml -llibopencv_objdetect -llibopencv_photo -llibopencv_stitching -llibopencv_video -llibopencv_videoio I get the following error.
/usr/bin/ld: cannot find -llibopencv_calib3d
/usr/bin/ld: cannot find -llibopencv_core
/usr/bin/ld: cannot find -llibopencv_dnn
/usr/bin/ld: cannot find -llibopencv_features2d
/usr/bin/ld: cannot find -llibopencv_flann
/usr/bin/ld: cannot find -llibopencv_highgui
/usr/bin/ld: cannot find -llibopencv_imgcodecs
/usr/bin/ld: cannot find -llibopencv_imgproc
/usr/bin/ld: cannot find -llibopencv_ml
/usr/bin/ld: cannot find -llibopencv_objdetect
/usr/bin/ld: cannot find -llibopencv_photo
/usr/bin/ld: cannot find -llibopencv_stitching
/usr/bin/ld: cannot find -llibopencv_video
/usr/bin/ld: cannot find -llibopencv_videoio
collect2: error: ld returned 1 exit status
I have also added a .conf file in /etc/ld.so.conf.d/opencv.conf with the line /usr/local/lib/ and issued the command sudo ldconfig. However, the issue remains.
I'd be grateful for any ideas or suggestions to resolve this issue.
-llibopencv_calib3d
make it
-lopencv_calib3d
etc. the lib part in front of it is simply wrong

Linking MKL in catkin_make / Cmake

I have a large codebase with multiple files and multiple Cmake files as well. The structure is src/folder1 src/folder2 etc and I run catkin_make -j1 from the src directory level. I am unable to link MKL. A small clip of the error is
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_sparse_d_xESB_SpMV_8_i4'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_spblas_zcoo0ssunc__mmout_par'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_spblas_zcoo1ntuuf__mmout_par'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_spblas_lp64_scsr0ntunc__smout_par'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_spblas_lp64_ccsr0nd_nc__svout_seq'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_spblas_ccoo1stlnf__svout_seq'
/usr/bin/ld: /opt/intel/oneapi/mkl/2021.3.0/lib/intel64/libmkl_intel_thread.so: undefined reference to `mkl_pds_pds_her_pos_fwd_ker_seq_nrhs_cmplx'
collect2: error: ld returned 1 exit status
I even added the following line to each cmake:
SET(GCC_COVERAGE_LINK_FLAGS " -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl")
The code does not use MKL BLAS directly but rather it is used by libraries like Opencv and Eigen (OpenCV was built with MKL).
I do define EIGEN_USE_MKL_ALL.
How do I link MKL?
You can make use of oneMKL link line advisor which recommends what are the required libraries and necessary compiler options for the use case on which you are working.
Here is the link
https://software.intel.com/content/www/us/en/develop/tools/oneapi/components/onemkl/link-line-advisor.html

Getting `undefined reference to 'glfwOpenWindowHint' ` error when trying to run OpenGL SuperBible example code on Linux

I'm trying to sun OpenGL SuperBible 6th edition example code for the first time on my Manjaro (arch) system.
I followed the HOWTOBUILD.txt, installed mesa and glfw (glfw-wayland, not sure if there is a difference) via pacman. Tried to run the first time unsuccessfuly, then changed an error in the CMakeList.txt as described in here https://stackoverflow.com/a/24474361/9197461
it got rid of the undefined reference to 'glfwInit' error, but all other undefined errors stayed. Can anyone help me compile this without errors?
code example:
https://github.com/openglsuperbible/sb6code
full error when I try to run make:
/usr/bin/ld: CMakeFiles/wrapmodes.dir/src/wrapmodes/wrapmodes.cpp.o: in function `sb6::application::run(sb6::application*)':
wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x8b): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xa1): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xb0): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xbf): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xd5): undefined reference to `glfwOpenWindowHint'
/usr/bin/ld: CMakeFiles/wrapmodes.dir/src/wrapmodes/wrapmodes.cpp.o:wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0xf5): more undefined references to `glfwOpenWindowHint' follow
/usr/bin/ld: CMakeFiles/wrapmodes.dir/src/wrapmodes/wrapmodes.cpp.o: in function `sb6::application::run(sb6::application*)':
wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x133): undefined reference to `glfwGetDesktopMode'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x18b): undefined reference to `glfwOpenWindow'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x1e9): undefined reference to `glfwOpenWindow'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x25b): undefined reference to `glfwSetMousePosCallback'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x267): undefined reference to `glfwSetMouseWheelCallback'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x280): undefined reference to `glfwEnable'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x289): undefined reference to `glfwDisable'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x29a): undefined reference to `glfwGetWindowParam'
/usr/bin/ld: wrapmodes.cpp:(.text._ZN3sb611application3runEPS0_[_ZN3sb611application3runEPS0_]+0x3bc): undefined reference to `glfwGetWindowParam'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/wrapmodes.dir/build.make:105: bin/wrapmodes] Error 1
make[1]: *** [CMakeFiles/Makefile2:296: CMakeFiles/wrapmodes.dir/all] Error 2
make: *** [Makefile:104: all] Error 2
I downloaded the source code and tried the steps you've done and not surpringsingly, received the same error message.
And it seems that the source code uses GLFW2 instead of GLFW3.
glfwOpenWindowHint is renamed to glfwWindowHint in GLFW3
See: glfwOpenWindowHint not declared in this scope GLFW3 & GLEW
You could try installing GLFW2 and run it again. Since GLFW2 is available in Ubuntu Xenial, remember to configure sources.list accordingly.
For OpenGL SuperBible 6th
EDIT:
I could not manage to install libglfw2 from Ubuntu Xenial repository. And manually installed dpkg from official website.
download .deb file from https://launchpad.net/ubuntu/xenial/+package/libglfw-dev
go to the folder .deb is installed in and run sudo dpkg -i [name of libglfw2].deb
Run find . -name "libglfw*" in /usr/lib to find the path to the library. (there can be multiple libglfw.so as you already downloaded GLFW3 so be careful)
Create a symbolic link for the dynamic library just installed by running the following command:
sudo ln -s /usr/lib/[path to file]/[filename] /usr/lib/[path to file]/libglfw2.so
Edit sb6code/CMakeFiles/tunnel.dir/link.txt as follows
-lglfw to -lglfw2
Run make
For OpenGL SuperBible 7th
If you have already installed libglfw3 but could not manage to run cmake .., this could be because your libglfw3.so is stored as libglfw.so.
In that case, you can create a symbolic link to it:
sudo ln -s /usr/lib/[path to file]/[libglfw name].so /usr/lib/[path to file]/libglfw3.so
Save and run cmake .. again inside build.
If it fails because of linker, make sure you have all the dependencies:
libglfw3-dev libx11-dev libxrandr-dev libxinerama-dev libxi-dev libxxf86vm-dev libxcursor-dev

CMake linking not finding libraries

I have a executable:
add_executable(treshhold src/main.cpp)
add_dependencies(treshhold ${PROJECT_NAME})
I have a directory
/opt/halcon/lib/x64-linux
which contains multiple .so files:
hAcqArgos3D-P1xx.so hAcqGigEVision.so hAcqMatrixVisionAcquire.so hAcquEye.so hioOPC_UA.so libhalconcpp.so libhalcon.so libhdevenginecpp.so
hAcqArgos3D-P1xxxl.so hAcqGigEVisionxl.so hAcqMatrixVisionAcquirexl.so hAcquEyexl.so hioOPC_UAxl.so libhalconcppxl.so libhalconxl.so libhdevenginecppxl.so
hAcqFile.so hAcqLPS36.so hAcqO3D3xx.so hAcqVideo4Linux2.so libhalconcpp10.so libhalconc.so libhdevenginecpp10.so libuastack.so
hAcqFilexl.so hAcqLPS36xl.so hAcqO3D3xxxl.so hAcqVideo4Linux2xl.so libhalconcpp10xl.so libhalconcxl.so libhdevenginecpp10xl.so libusb-1.0-usan.so.0
linked used using and tried both:
include_directories(/opt/halcon/lib/x64-linux)
link_directories(/opt/halcon/lib/x64-linux)
But when i try a to link a certain library
target_link_libraries(treshhold libhalconc)
i get the error:
[ 50%] Linking CXX executable treshhold
/usr/bin/ld: cannot find -llibhalconc
And if i try not to make the target link i get the missing reference error from the compiler.
EDIT Full file:
cmake_minimum_required(VERSION 2.8.3)
project(ros_halcon_bridge)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
)
add_executable(treshhold src/main.cpp)
add_dependencies(treshhold ${PROJECT_NAME})
include_directories(/opt/halcon/lib/x64-linux)
link_directories(/opt/halcon/lib/x64-linux)
target_link_libraries(treshhold libhalconc)
EDIT2
I would want to add all libraries with the following:
target_link_libraries(treshhold hAcqArgos3D-P1xx.so hAcqGigEVision.so hAcqMatrixVisionAcquire.so hAcquEye.so hioOPC_UA.so libhalconcpp.so libhalcon.so libhdevenginecpp.so hAcqArgos3D-P1xxxl.so hAcqGigEVisionxl.so hAcqMatrixVisionAcquirexl.so hAcquEyexl.so hioOPC_UAxl.so libhalconcppxl.so libhalconxl.so libhdevenginecppxl.so hAcqFile.so hAcqLPS36.so hAcqO3D3xx.so hAcqVideo4Linux2.so libhalconcpp10.so libhalconc.so libhdevenginecpp10.so libuastack.so hAcqFilexl.so hAcqLPS36xl.so hAcqO3D3xxxl.so hAcqVideo4Linux2xl.so libhalconcpp10xl.so libhalconcxl.so libhdevenginecpp10xl.so libusb-1.0-usan.so.0)
but that results in:
[ 50%] Linking CXX executable treshhold
/usr/bin/ld: cannot find -lhAcqArgos3D-P1xx
/usr/bin/ld: cannot find -lhAcqGigEVision
/usr/bin/ld: cannot find -lhAcqMatrixVisionAcquire
/usr/bin/ld: cannot find -lhAcquEye
/usr/bin/ld: cannot find -lhioOPC_UA
/usr/bin/ld: cannot find -lhalconcpp
/usr/bin/ld: cannot find -lhalcon
/usr/bin/ld: cannot find -lhdevenginecpp
/usr/bin/ld: cannot find -lhAcqArgos3D-P1xxxl
/usr/bin/ld: cannot find -lhAcqGigEVisionxl
/usr/bin/ld: cannot find -lhAcqMatrixVisionAcquirexl
/usr/bin/ld: cannot find -lhAcquEyexl
/usr/bin/ld: cannot find -lhioOPC_UAxl
/usr/bin/ld: cannot find -lhalconcppxl
/usr/bin/ld: cannot find -lhalconxl
/usr/bin/ld: cannot find -lhdevenginecppxl
/usr/bin/ld: cannot find -lhAcqFile
/usr/bin/ld: cannot find -lhAcqLPS36
/usr/bin/ld: cannot find -lhAcqO3D3xx
/usr/bin/ld: cannot find -lhAcqVideo4Linux2
/usr/bin/ld: cannot find -lhalconcpp10
/usr/bin/ld: cannot find -lhalconc
/usr/bin/ld: cannot find -lhdevenginecpp10
/usr/bin/ld: cannot find -luastack
/usr/bin/ld: cannot find -lhAcqFilexl
/usr/bin/ld: cannot find -lhAcqLPS36xl
/usr/bin/ld: cannot find -lhAcqO3D3xxxl
/usr/bin/ld: cannot find -lhAcqVideo4Linux2xl
/usr/bin/ld: cannot find -lhalconcpp10xl
/usr/bin/ld: cannot find -lhalconcxl
/usr/bin/ld: cannot find -lhdevenginecpp10xl
/usr/bin/ld: cannot find -lusb-1.0-usan
You can see what CMake is doing with
make VERBOSE=1
Then you should be able to find out what's wrong with the generated command.
Only once you're sure about the command you really want should you bother with how to write it correctly with cmake

Opencv library files cannot find in eclipse

I am trying to develop a simple c++ project which uses opencv.I followed http://docs.opencv.org/doc/tutorials/introduction/linux_eclipse/linux_eclipse.html website.
But eclipse shows errors like
/usr/bin/ld: cannot find -llibopencv_photo
/usr/bin/ld: cannot find -llibopencv_stitching
/usr/bin/ld: cannot find -llibopencv_superres
/usr/bin/ld: cannot find -llibopencv_ts
/usr/bin/ld: cannot find -llibopencv_video
/usr/bin/ld: cannot find -llibopencv_videostab
/usr/bin/ld: cannot find -llibopencv_calib3d
/usr/bin/ld: cannot find -llibopencv_contrib
/usr/bin/ld: cannot find -llibopencv_ocl
/usr/bin/ld: cannot find -llibopencv_core
/usr/bin/ld: cannot find -llibopencv_core
/usr/bin/ld: cannot find -llibopencv_flann
/usr/bin/ld: cannot find -llibopencv_gpu
/usr/bin/ld: cannot find -llibopencv_highgui
/usr/bin/ld: cannot find -llibopencv_imgproc
/usr/bin/ld: cannot find -llibopencv_legacy
/usr/bin/ld: cannot find -llibopencv_ml
/usr/bin/ld: cannot find -llibopencv_nonfree
/usr/bin/ld: cannot find -llibopencv_objdetect
collect2: ld returned 1 exit status
make: *** [MyProject] Error 1`
I have included libraries and their paths in the following ways.
Project–>Properties
In C/C++ Build ->Settings.
In GCC C++ Compiler ->Includes.
In Include paths(-l) I have added /usr/local/include/opencv.
In GCC C++ Linker
I have added the path (-L) as /usr/local/lib and also library names.
Can anyone please tell me what the reason for this errors?
you have to add the library names without the prefix 'lib'