I tried to follow this tutorial to install opencv ubuntu 14.04. I created a C ++ project in QT, after the execution of this. an error message is displayed:
g++ -m64 -o test main.o mainwindow.o moc_mainwindow.o
-L/usr/X11R6/lib64 -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
-lopencv_xfeatures2d -lopencv_imgcodecs -lQt5Widgets -L/usr/lib/x86_64-linux-gnu -lQt5Gui -lQt5Core -lGL -lpthread
//error is here
/usr/bin/ld: cannot find -lopencv_contrib
/usr/bin/ld: cannot find -lopencv_legacy
/usr/bin/ld: cannot find -lopencv_xfeatures2d
collect2: error: ld returned 1 exit status
make: *** [test] Error 1
06:00:12: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project test (kit: Desktop)
When executing step 'Make'
Thank you :)
Related
I'm trying to compile and run OpenCV through the command line. I can get the main Open CV libraries to work however I think my problem is with using the opencv_contrib libraries.
I have installed Open CV with home brew.
I can compile and run the below code fine from another SO question:
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main( int argc, char** argv )
{
Mat src = Mat(Size(320,240),CV_64F);;
namedWindow("test");
cout << "press any key to close" << endl;
while(true){
randn(src,0,1.0);
imshow("test",src);
if(waitKey() > 0) break;
}
}
This is compiled like this:
g++ cv.cpp -I"/usr/local/Cellar/opencv/3.4.1_5/include" -L"/usr/local/Cellar/opencv/3.4.1_5/lib/" -lopencv_core -lopencv_highgui -o cv
Then ran ./main
However when I try and run anything with the opencv_contrib libraries I get this error when compiled like this:
g++ cv.cpp -I"/usr/local/Cellar/opencv/3.4.1_5/include" -L"/usr/local/Cellar/opencv/3.4.1_5/lib/" -I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -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 -o cv
error:
Undefined symbols for architecture x86_64:
"cv::xfeatures2d::SURF::create(double, int, int, bool, bool)", referenced from:
_main in cv-f48298.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I believe this is likely due to not specifying the opencv_contrib libraries. I understand they come installed with homebrew. In my Cellar directory I have a directory for opencv and opencv_contrib. I'm not sure if the opencv_contrib directory needs to be located within the opencv directory.
But I believe everything is there as with this:
pkg-config --libs --cflags opencv
It outputs:
-I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -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
But then if I add that to my command like:
g++ cv.cpp -I"/usr/local/Cellar/opencv/3.4.1_5/include" -L"/usr/local/Cellar/opencv/3.4.1_5/lib/" pkg-config --libs --cflags opencv -o cv
I get this:
clang: error: unsupported option '--libs'
clang: error: unsupported option '--cflags'
clang: error: no such file or directory: 'pkg-config'
clang: error: no such file or directory: 'opencv'
I'm able to compile the same code in Xcode and I only needed to add the search paths for the openCV directory and add the libs within there. I can run the code by opening the products folder in finder and running ./cv with images passed in. But I'm struggling with doing this all through the command line.
Any help would be great!
You want to add the output of the pkgconfig tool (you listed it above: -I/usr/local/include/opencv ...) to your compilation command line to compile correctly.
You could just manually copy this output text into your compiler invocation command:
g++ cv.cpp -I"/usr/local/Cellar/opencv/3.4.1_5/include" -L"/usr/local/Cellar/opencv/3.4.1_5/lib/" -I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -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 -o cv
This is usually automated by calling pkgconfig inline:
g++ cv.cpp -I"/usr/local/Cellar/opencv/3.4.1_5/include" -L"/usr/local/Cellar/opencv/3.4.1_5/lib/" `pkg-config --libs --cflags opencv` -o cv
Notice the backticks in this though - they are missing in your command line. With the backticks pkgconfig will be executed and the output (which you know what it looks like) will be inserted into the command line.
I'm going step by step like this guide and my code does not compile. It has gotten some linker errors which I don't know how to fix. this is my terminal's answer to : pkg-config --libs opencv
/usr/lib/x86_64-linux-gnu$ pkg-config --libs opencv
/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so -lopencv_calib3d
/usr/lib/x86_64-linux-gnu/libopencv_contrib.so -lopencv_contrib
/usr/lib/x86_64-linux-gnu/libopencv_core.so -lopencv_core
/usr/lib/x86_64-linux-gnu/libopencv_features2d.so -lopencv_features2d
/usr/lib/x86_64-linux-gnu/libopencv_flann.so -lopencv_flann
/usr/lib/x86_64-linux-gnu/libopencv_gpu.so -lopencv_gpu
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so -lopencv_highgui
/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so -lopencv_imgproc
/usr/lib/x86_64-linux-gnu/libopencv_legacy.so -lopencv_legacy
/usr/lib/x86_64-linux-gnu/libopencv_ml.so -lopencv_ml
/usr/lib/x86_64-linux-gnu/libopencv_objdetect.so -lopencv_objdetect
/usr/lib/x86_64-linux-gnu/libopencv_ocl.so -lopencv_ocl
/usr/lib/x86_64-linux-gnu/libopencv_photo.so -lopencv_photo
/usr/lib/x86_64-linux-gnu/libopencv_stitching.so -lopencv_stitching
/usr/lib/x86_64-linux-gnu/libopencv_superres.so -lopencv_superres
/usr/lib/x86_64-linux-gnu/libopencv_ts.so -lopencv_ts
/usr/lib/x86_64-linux-gnu/libopencv_video.so -lopencv_video
/usr/lib/x86_64-linux-gnu/libopencv_videostab.so -lopencv_videostab
sorry if it's a mess to read but this is exactly how I received the answer.
This is how I've organized my linker
this is the error I get:
Building target: Ball_Plate Invoking: GCC C++ Linker g++ -L/usr/lib/x86_64-linux-gnu -o"Ball_Plate" ./Src/src.o -lopencv_core\ opencv_imgproc\ opencv_highgui\ opencv_ml\ opencv_video\ opencv_features2d\ opencv_calib3d\ opencv_objdetect\
opencv_contrib\ opencv_legacy\ opencv_flann /usr/bin/ld: cannot find
-lopencv_core opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_features2d opencv_calib3d opencv_objdetect opencv_contrib
opencv_legacy opencv_flann collect2: error: ld returned 1 exit status
makefile:45: recipe for target 'Ball_Plate' failed make: ***
[Ball_Plate] Error 1
I don't know how to fix this, I don't know much about how linker works around .so files and I would appreciate that if you could help me.
So I read this post and found out what the problem was, tried to compile the OpenCV library with -DBUILD_TIFF=ON, Now Eclipse can find the header files but I get linker errors again, Eclipse cannot link the libraries.
I'm trying to complie opencv-3.1.0/samples/gpu/surf_keypoint_matcher.cpp through:
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib/ -g -o binary surf_keypoint_matcher.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_stitching -lopencv_imgcodecs -lopencv_xfeatures2d
But I'm getting this error:
/tmp/ccQW7t3Z.o: In function `main':
/home/luca/Downloads/opencv-3.1.0/samples/gpu/surf_keypoint_matcher.cpp:65: undefined reference to `cv::cuda::DescriptorMatcher::createBFMatcher(int)'
collect2: error: ld returned 1 exit status
Why?
Your error message:
/home/luca/Downloads/opencv-3.1.0/samples/gpu/surf_keypoint_matcher.cpp:65: undefined reference to `cv::cuda::DescriptorMatcher::createBFMatcher(int)'
collect2: error: ld returned 1 exit status
shows that you have an undefined reference to cv::cuda::DescriptorMatcher::createBFMatcher
this resides in the cuda libs so you need to include the appropriate headers and link into the following libs as opencv_cudafeatures2d depends on them:
opencv_cudafilters
opencv_cudawarping
opencv_features2d
opencv_cudaarithmn
opencv_flann
opencv_core
certainly this is true for opencv version 3.1.0 which is what I'm using
DescriptorMatcher is in cudafeatures2d.hpp. So, you have to include the header cudafeatures2d.hpp in the .cpp program and link the library in the compile process.
The program runs if you use this -lopencv_cudafeatures2d:
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib/ -g -o binary surf_gpu_probe1.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_stitching -lopencv_imgcodecs -lopencv_xfeatures2d -lopencv_cudafeatures2d
I have faced problem during OpenCv cross-comipilation
(with OpenWrt, release Attitude Adjustment (12.09-rc1), platform ar71xx).
It seems that OpenWRt linker could not find proper libraries...
[ 27%] Built target opencv_ts
Linking CXX executable ../../bin/opencv_perf_core
mips-openwrt-linux-uclibc-g++.bin: warning: environment variable 'STAGING_DIR' not defined
mips-openwrt-linux-uclibc-g++.bin: warning: environment variable 'STAGING_DIR' not defined
/home/pawel/openwrt/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: skipping incompatible /usr/lib/gcc/i686-linux-gnu/4.8/libstdc++.so when searching for -lstdc++
/home/pawel/openwrt/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: skipping incompatible /usr/lib/gcc/i686-linux-gnu/4.8/libstdc++.a when searching for -lstdc++
/home/pawel/openwrt/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: cannot find -lv4l1
/home/pawel/openwrt/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: cannot find -lavcodec
/home/pawel/openwrt/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: cannot find -lavformat
/home/pawel/openwrt/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: cannot find -lavutil
/home/pawel/openwrt/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: cannot find -lswscale
/home/pawel/openwrt/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: cannot find -lbz2
/home/pawel/openwrt/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: cannot find -lz
/home/pawel/openwrt/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: skipping incompatible /usr/lib/gcc/i686-linux-gnu/4.8/libstdc++.so when searching for -lstdc++
/home/pawel/openwrt/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: skipping incompatible /usr/lib/gcc/i686-linux-gnu/4.8/libstdc++.a when searching for -lstdc++
collect2: ld returned 1 exit status
make[2]: *** [bin/opencv_perf_core] Błąd 1
make[1]: *** [modules/core/CMakeFiles/opencv_perf_core.dir/all] Błąd 2
make: *** [all] Błąd 2`
I stacked here and I am not able to move on so I am looking for some help.
I would not compile OpenCv with OpenWRT but when I was trying to use libs from here and here
I got following error :
Building target: misp
Invoking: Cross G++ Linker
mips-openwrt-linux-g++ -L/home/prog12/openwrtD/openwrt/opencv_libs/ar71xx-WR703N/debug/ -o "misp" ./src/main.o -lopencv_highgui -lopencv_core -lopencv_imgproc -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
mips-openwrt-linux-uclibc-g++.bin: warning: environment variable 'STAGING_DIR' not defined
mips-openwrt-linux-uclibc-g++.bin: warning: environment variable 'STAGING_DIR' not defined
/home/prog12/openwrtD/openwrt/opencv_libs/ar71xx-WR703N/debug//libopencv_core.a(system.cpp.o): In function `cv::Mutex::Mutex()':
system.cpp:(.text._ZN2cv5MutexC2Ev+0x38): undefined reference to `pthread_spin_init'
system.cpp:(.text._ZN2cv5MutexC2Ev+0x40): undefined reference to `pthread_spin_init'
/home/prog12/openwrtD/openwrt/opencv_libs/ar71xx-WR703N/debug//libopencv_core.a(system.cpp.o): In function `cv::Mutex::~Mutex()':
system.cpp:(.text._ZN2cv5MutexD2Ev+0x78): undefined reference to `pthread_spin_destroy'
system.cpp:(.text._ZN2cv5MutexD2Ev+0x80): undefined reference to `pthread_spin_destroy'
/home/prog12/openwrtD/openwrt/opencv_libs/ar71xx-WR703N/debug//libopencv_core.a(system.cpp.o): In function `cv::Mutex::operator=(cv::Mutex const&)':
system.cpp:(.text._ZN2cv5MutexaSERKS0_+0xa4): undefined reference to `pthread_spin_destroy'
system.cpp:(.text._ZN2cv5MutexaSERKS0_+0xac): undefined reference to `pthread_spin_destroy'
Is there someone who could help me?
EDITED:
Also faced problem adding zlib( thx to old-ufo).
Building target: misp
Invoking: Cross G++ Linker
mips-openwrt-linux-g++ -L/home/prog12/openwrtD/openwrt/opencv_libs/ar71xx-WR703N/debug/ -o "misp" ./src/main.o -lpthread -lzlib -lopencv_highgui -lopencv_core -lopencv_imgproc -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
mips-openwrt-linux-uclibc-g++.bin: warning: environment variable 'STAGING_DIR' not defined
mips-openwrt-linux-uclibc-g++.bin: warning: environment variable 'STAGING_DIR' not defined
/home/prog12/openwrt/OpenWrt-Toolchain-ar71xx-for-mips_r2-gcc-4.6-linaro_uClibc-0.9.33.2/toolchain-mips_r2_gcc-4.6-linaro_uClibc-0.9.33.2/bin/../lib/gcc/mips-openwrt-linux-uclibc/4.6.3/../../../../mips-openwrt-linux-uclibc/bin/ld: cannot find -lzlib
It is linking problem - you have to specify all libraries, you have used functions from. In this case - link also with -lzlib - lpthread options.
For the all similar problems - google function on which you get an error and find to which library it belongs. Then link to it.
first I would like to state that I'm a very noob at c++. I am using to compile and run code from Features2D + Homography to find a known object tutorial, but I think I'm having trouble in linking correctly the libraries needed. I am getting this:
Invoking: GCC C++ Linker g++ -L/usr/local/lib -o "Homografia2"
./src/Homografia2.o -lopencv_core -lopencv_nonfree -lopencv_imgproc
-lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o: In
function _start': (.text+0x18): undefined reference tomain'
collect2: ld returned 1 exit status make: * [Homografia2] Error 1
**** Build Finished ****
I'm working on eclipse. Please, I really need help.
The error is clear main function was not found. Are you missing it?
int main(int argc, char *argv[]){
//start application.
}
Regards