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.
Related
I was trying to build a repo located HERE. As per instructions, I created a CMakeLists, and updated the directory addresses inside. I was not sure about the OpenCV path, but found two candidates and inserted both.
Cmake is good, but when doing make, I get this error, which I guess is maybe due to the openCV path being incorrect.
Here is the VERBOSE output:
[100%] Linking CXX executable SimpleVideoSummExample
/usr/bin/cmake -E cmake_link_script CMakeFiles/SimpleVideoSummExample.dir/link.txt --verbose=1
/usr/bin/c++ -O3 -std=c++0x -std=c++0x -fopenmp -s CMakeFiles/SimpleVideoSummExample.dir/src/utils/ShotDetector.cc.o CMakeFiles/SimpleVideoSummExample.dir/src/videoSummarization/SimpleVideoSummarizer.cc.o CMakeFiles/SimpleVideoSummExample.dir/src/utils/ColorUtils.cc.o CMakeFiles/SimpleVideoSummExample.dir/src/utils/ImageUtils.cc.o CMakeFiles/SimpleVideoSummExample.dir/examples/SimpleVideoSummExample.cc.o -o SimpleVideoSummExample -L/usr/local/Cellar/opencv/3.4.1_2/lib -rdynamic libsummengine.a -lopencv_imgproc -lopencv_core -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_bgsegm -lopencv_video -lopencv_objdetect -lopencv_dnn -Wl,-rpath,/usr/local/Cellar/opencv/3.4.1_2/lib
/usr/bin/ld: cannot find -lopencv_bgsegm
collect2: error: ld returned 1 exit status
CMakeFiles/SimpleVideoSummExample.dir/build.make:199: recipe for target 'SimpleVideoSummExample' failed
make[2]: *** [SimpleVideoSummExample] Error 1
What is the problem? How to fix it?
Here is the directory part of CMakeLists (Cellar is the git repo's user):
include_directories(/usr/local/Cellar/opencv/3.4.1_2/include/ /usr/local/Cellar/opencv/3.4.1_2/include/opencv/ /usr/include/opencv /usr/local/include/opencv$
link_directories(/usr/local/Cellar/opencv/3.4.1_2/lib/)
add_executable(SimpleVideoSummExample src/utils/ShotDetector.cc src/videoSummarization/SimpleVideoSummarizer.cc src/utils/ColorUtils.cc src/utils/ImageUtils$
target_link_libraries(SimpleVideoSummExample
summengine -lopencv_imgproc
-lopencv_core
-lopencv_highgui
-lopencv_videoio
-lopencv_imgcodecs
-lopencv_bgsegm
-lopencv_video
-lopencv_objdetect
-lopencv_dnn
)
Although the Github repository you are using doesn't explicitly state it in the documentation, it appears you not only need OpenCV, but also need to build the extra OpenCV modules (hinted by this answer). The missing opencv_bgsegm library is provided by these "extra" OpenCV modules.
Following a tutorial such as this, you should include the CMake definition flag:
-DOPENCV_EXTRA_MODULES_PATH=/path/to/opencv_contrib/modules/
when running cmake. This will ensure the extra modules are built, and the opencv_bgsegm library will be available on your system.
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 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 :)
I'm trying to compile the 'motemple.c' that comes with the opencv samples in Ubuntu 14.04 environment. I think that opencv has been properly installed; most of the programs are running as expected. However, when compiling the above mentioned file, an error "undefined reference" is raised for several functions. Below is the output of the compilation:
Building target: ACTION_detection1
Invoking: Cross G++ Linker
g++ -L/usr/local/lib -o "ACTION_detection1" ./opencvexample/MotionSegmentation.o -lopencv_core -lopencv_photo -lopencv_videoio -lopencv_videostab -lopencv_imgcodecs -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
./opencvexample/MotionSegmentation.o: In function `update_mhi':
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:103: undefined reference to `cvUpdateMotionHistory'
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:105: undefined reference to `cvUpdateMotionHistory'
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:114: undefined reference to `cvCalcMotionGradient'
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:123: undefined reference to `cvSegmentMotion'
/media/thanuja/DTR_DATA/ACTION-TV/ACTIONDETECTION/Implementations/ACTION_detection1/Debug/../opencvexample/MotionSegmentation.cpp:149: undefined reference to `cvCalcGlobalOrientation'
collect2: error: ld returned 1 exit status
make: *** [ACTION_detection1] Error 1
As it can be seen, I have linked all the opencv libraries to mu Eclipse project. I also tried the command line solution provided here, but still get the same error.
they have been replaced to the opencv_contrib from the main repository. You can find them in the optflow module.
Notice: cvUpdateMotionHistory, cvCalcMotionGradient, etc. is the name of OpenCV 1.x API functions, they are now obsoleted/outdated so try to avoid them by replacing to cv::updateMotionHistory, cv::calcMotionGradient, etc.
this is maybe a noob question but I've been stuck for a while and I appreciate any help...
I have been able to install opencv and run a sample application using the terminal without any problems however I want to use eclipse to manage my project easily...
I have followed the instructions given by the opencv tutorial in this [link]
http://docs.opencv.org/doc/tutorials/introduction/linux_eclipse/linux_eclipse.html
I followed everything and i still get the following errors
/usr/bin/ld: cannot find -llibopencv_calib3d
/usr/bin/ld: cannot find -llibopencv_contrib
/usr/bin/ld: cannot find -llibopencv_core
/usr/bin/ld: cannot find -llibopencv_features2d
/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
/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
collect2: error: ld returned 1 exit status
make: *** [Test_OpenCV01] Error 1
the only differences I was able to find between my steps and the tutorial is:
when i run the command :
pkg-config --libs opencv
this is my output
/usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_superres.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so
so the library names are a bit different so I use the names that I have.
the command line that was executed automaticly from eclipse is
g++ -L/usr/local/lib/ -o "Test_OpenCV01" ./src/main.o -llibopencv_calib3d -llibopencv_contrib -llibopencv_core -llibopencv_features2d -llibopencv_flann -llibopencv_gpu -llibopencv_highgui -llibopencv_imgproc -llibopencv_legacy -llibopencv_ml -llibopencv_nonfree -llibopencv_objdetect -llibopencv_photo -llibopencv_stitching -llibopencv_superres -llibopencv_ts -llibopencv_video -llibopencv_videostab
it clearly specifies that the library path is /usr/local/lib/ which is where the shared libraries are at however in the error it says that it can't find the lib files in /usr/bin/ld
p.s.
I have tried both
1)Configuring OpenCV for using shared libraries:
sudo gedit /etc/ld.so.conf.d/opencv.conf
and adding the following line at the end of the file
/usr/local/lib the running sudo ldconfig after saving.
2)run the command
export LD_LIBRARY_PATH=/usr/local/lib
I also added
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
to the end of the /etc/bash.bashrc file.
Thanks for your help in advanced.
Your linking step is specifying the libraries incorrectly. If the library is libfoo.so, then you need to say -lfoo.
Replace
g++ -L/usr/local/lib/ -o "Test_OpenCV01" ./src/main.o -llibopencv_calib3d -llibopencv_contrib -llibopencv_core -llibopencv_features2d -llibopencv_flann -llibopencv_gpu -llibopencv_highgui -llibopencv_imgproc -llibopencv_legacy -llibopencv_ml -llibopencv_nonfree -llibopencv_objdetect -llibopencv_photo -llibopencv_stitching -llibopencv_superres -llibopencv_ts -llibopencv_video -llibopencv_videostab
with
g++ -L/usr/local/lib/ -o "Test_OpenCV01" ./src/main.o -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_superres -lopencv_ts -lopencv_video -lopencv_videostab
You can read more about linking options here.
Even though the file names are like liblibopencv_core.so under /usr/local/lib folder, in GCC C++ linker libraries just mention opencv_core. Do the same for other files you are adding in library.