DSO missing from command line opencv - opencv

I ran this command
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib/ -g -o binary DisplayImage.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_stitching
I am getting this error
/usr/bin/ld: /tmp/ccB73ml3.o: undefined reference to symbol
'_ZN2cv6imreadERKNS_6StringEi'
//usr/local/lib/libopencv_imgcodecs.so.3.0: error adding symbols: DSO
missing from command line
I dont know what order it should be the linking

Related

Why do I get an error when compiling opencv code with make even if the particular missing files exist?

I've got the following makefile:
OBJS:= main.o
CV_LIBS:= -I/usr/local/include/opencv4 -I/usr/local/include -L/usr/local/lib/ -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
main: $(OBJS)
g++ $(OBJS) $(CV_LIBS) -O3 -ffast-math -o main -Wall -g
main.o: main.h
g++ -c main.cpp -Wall -g
My main.h file has the following line:
#include <opencv4/opencv2/objdetect.hpp>
I get the following error:
/usr/local/include/opencv4/opencv2/objdetect.hpp:47:10: fatal error: opencv2/core.hpp: No such file or directory
47 | #include "opencv2/core.hpp"
I have tried the following as well with no luck:
#include <opencv2/objdetect.hpp>
Error:
main.h:4:10: fatal error: opencv2/objdetect.hpp: No such file or directory
I can confirm there is an objdetect.hpp in both:
/usr/local/include/opencv4/opencv2/ and
/usr/local/include/opencv4/opencv2/objdetect.hpp
I have looked at this question, but unfortunately I'm not using cmake. What am I doing wrong? Many thanks.
If you look at the compile line that make prints out (which you didn't include in your question), it's pretty straightforward why you get this error.
The compile line, that compiles main.c into main.o, looks like this:
g++ -c main.cpp -Wall -g
You can clearly see that there is no reference to the directories you need to include header files here.
Your makefile has this:
CV_LIBS:= -I/usr/local/include/opencv4 -I/usr/local/include -L/usr/local/lib/ -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
where you are combining compiler flags, such as -I, with linker flags, such as -L and -l in the same variable, calling them all "LIBS", and adding them only to the link line.
You need to put the compiler flags into the compile command, and the linker flags into the link command:
CPPFLAGS = -I/usr/local/include/opencv4 -I/usr/local/include
CV_LIBS = -L/usr/local/lib/ -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
main: $(OBJS)
g++ $(OBJS) $(CV_LIBS) -O3 -ffast-math -o main -Wall -g
main.o: main.h
g++ $(CPPFLAGS) -c main.cpp -Wall -g
FYI, it's more correct for you to use #include <opencv2/objdetect.hpp> in your source code, not #include <opencv4/opencv2/objdetect.hpp>

"opencv2: no such file or directory" while trying to build Darknet?

I am trying to use Darkent with OpenCV and CUDA. I installed darknet according to these instructions:
https://pjreddie.com/darknet/install/
I installed CUDA according to these instructions:
https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html
Finally, I installed OpenCV according to these instructions:
http://www.linuxfromscratch.org/blfs/view/svn/general/opencv.html
I then added the following lines to the end of my bashrc:
export PATH=/usr/local/cuda-11.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
Next, I modified the Makefile in the darknet directory such that GPU=1, and OPENCV=1. I remade, and ran into a bunch of repeated errors saying:
No package 'opencv' found
gcc -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv` -DGPU -I/usr/local/cuda/include/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -DOPENCV -DGPU -c ./src/lstm_layer.c -o obj/lstm_layer.o
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
I checked, and although I had added the directory "/usr/local/lib/pkgconfig" to my PKG_CONFIG_PATH, there was no opencv.pc file there. I googled this, and read an answer that suggested to create the file manually, so this is what I did, with the following content:
prefix=/usr
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Name: opencv
Description: The opencv library
Version: 2.x.x
Cflags: -I${includedir}/opencv -I${includedir}/opencv2
Libs: -L${libdir} -lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -l
This solved the repeating error mentioned above, but I am still getting a similar error when I make:
./src/image_opencv.cpp:5:10: fatal error: opencv2/opencv.hpp: No such file or directory
5 | #include "opencv2/opencv.hpp"
| ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
I'm not sure if I fixed the first issue, and this is a separate one, or if the first fix just fixed a symptom, and not the problem. Since then, I also tried:
sudo apt install libopencv-dev
to no effect.
pkg-config --modversion
produces: 2.x.x
pkg-config --cflags opencv
produces:
[code]
-I/usr/include/opencv -I/usr/include/opencv2
[/code]
Any help would be greatly appreciated. I am running ubuntu 20.04, kernel 5.4.0-53-generic.
I tried this and it worked, create opencv.pc file with these contents:
# Package Information for pkg-config
prefix=/usr
exec_prefix=${prefix}
libdir=${prefix}/lib/x86_64-linux-gnu
includedir_new=${prefix}/include/opencv4
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.5.0
Libs: -L${libdir} -lopencv_dnn -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core
Libs.private: -ldl -lm -lpthread -lrt
Cflags: -I${includedir_new}
and place it in /usr/local/lib/pkgconfig/.

Trying to compile character_recognition.cpp from opencv_contrib samples

I've just installed opencv 3.2 and tesseract module. Now I'm tryng to compile the character_recognition.cpp sample in the opencv_contrib folder. If I use the command pkg-config --cflags --libs opencv it displays
-I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dpm -lopencv_freetype -lopencv_fuzzy -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_plot -lopencv_dnn -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core
But if I try to compile che cpp file
g++ -ggdb `pkg-config --cflags --libs opencv` character_recognition.cpp -o character_recognition
it says me that cv::imread(cv::String const&, int) it's not defined and this kind of error for every function of the opencv libraries that is used in the code.
Seems thats I can't link the libraries. Can you help me?

Compile OpenCV code with icc and mmic flag

I need to use OpenCV+FFMPEG in a Xeon Phi without root permission.
My environment is:
OpenCV version: 3.1.0
Host OS: Linux
Target OS: Phi Co-Processor
Compiler & CMake: ICC 15.0.2 & CMake 3.5.2 (installed in my home)
When I compile OpenCV with GCC in my home, it works fine. I compile with
cmake -D CMAKE_INSTALL_PREFIX=$HOME/lib/opencv-3.1.0 -D WITH_GTK=ON ..
all works fine by setting LD_CONFIG_PATH and PKG_CONFIG_PATH env variables od ffmpeg and opencv.
Now, i need to use my code in a PHi CoProcessor, so I compile my code with
icc -mmic -Wall -std=c++11 -DNO_DEFAULT_MAPPING -I /home/spm1407/lib/opencv-3.1.0/include/ -I /home/spm1501/fastflow/ -O3 -o farm farm.cpp -pthread -L/home/spm1407/lib/opencv-3.1.0/lib -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_videoio -lopencv_video -lopencv_imgproc -lpthread
(Please ignore FastFlow)
Compiler returns
x86_64-k1om-linux-ld: skipping incompatible /home/spm1407/lib/opencv-3.1.0/lib/libopencv_core.so when searching for -lopencv_core
x86_64-k1om-linux-ld: cannot find -lopencv_core
x86_64-k1om-linux-ld: skipping incompatible /home/spm1407/lib/opencv-3.1.0/lib/libopencv_highgui.so when searching for -lopencv_highgui
x86_64-k1om-linux-ld: cannot find -lopencv_highgui
x86_64-k1om-linux-ld: skipping incompatible /home/spm1407/lib/opencv-3.1.0/lib/libopencv_imgcodecs.so when searching for -lopencv_imgcodecs
x86_64-k1om-linux-ld: cannot find -lopencv_imgcodecs
x86_64-k1om-linux-ld: skipping incompatible /home/spm1407/lib/opencv-3.1.0/lib/libopencv_videoio.so when searching for -lopencv_videoio
x86_64-k1om-linux-ld: cannot find -lopencv_videoio
x86_64-k1om-linux-ld: skipping incompatible /home/spm1407/lib/opencv-3.1.0/lib/libopencv_video.so when searching for -lopencv_video
x86_64-k1om-linux-ld: cannot find -lopencv_video
x86_64-k1om-linux-ld: skipping incompatible /home/spm1407/lib/opencv-3.1.0/lib/libopencv_imgproc.so when searching for -lopencv_imgproc
x86_64-k1om-linux-ld: cannot find -lopencv_imgproc
if i omit mmic flag, compiler works fine.
How can i resolve this issue? Any suggest?
Thanks.

opencv 2.4 SIFT compile error

openCV has changed feature detectors/descriptors (as usually) with new version. I've already found, that I need to add
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/nonfree/features2d.hpp"
however, it still doesn`t work. The error I get is:
error: ‘cv::SIFT::DetectorParams’ has not been declare
I use standard command for building
gcc `pkg-config --cflags --libs opencv` -o descriptorExtractor main.cpp
and all the libraries, etc. should be linked correctly
pkg-config --cflags --libs opencv
-I/opt/ros/fuerte/include/opencv -I/opt/ros/fuerte/include -L/opt/ros/fuerte/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_ts -lopencv_video -lopencv_videostab
What's wrong with openCV again? Please, don't ask me why do I need SIFT from openCV and not from some other software or binary, I just need it...
I do not remember it well... but I think the issue was that I didn't use
cv::initModule_nonfree();

Resources