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.
Related
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 installed OpenCV 3.2.0-dev on my mac(10.12) using Homebrew following this instruction http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/.
I solved the QTKit.h problem by skipping the checkout step.
Then I tried to build a small c++ program in Xcode 8 because I'm more familiar with c++ than python, it gave me an Apple mach-O linker (id) error which is shown here:
error message screenshot
The search paths for header and library are /usr/local/include and /usr/local/lib respectively. And the linker flags are
-lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videoio -lopencv_videostab
And I know when I use OpenCV version later than 3.1(I think), the linker flags can be replaced by something like opencv_world310.lib. Is there a similar way in Xcode?
Anyone can help me with that?
Homebrew install opencv in /usr/local/Cellar/, not in /usr/local/. So you need to modify header and library search paths correspondingly.
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
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
Recently I build opencv as static library(by using BUILD_SHARED_LIBS=OFF) while dynamic libraries are already there, but at different location. And when I build may program I am getting many error. I am using command line for compiling the code, and look like below.
g++ -static -I$(OpenCV_Static_Build)/include/opencv -L$(OpenCV_Static_Build)/lib/ -g -o binary main.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy
The error look like,
grfmt_tiff.cpp:(.text._ZN2cv11TiffEncoder12writeLibTiffERKNS_3MatERKSt6vectorIiSaIiEE+0x167): undefined reference to `TIFFSetField'
window_gtk.cpp:(.text.cvNamedWindow+0x29d): undefined reference to `g_type_check_instance_cast'
/usr/lib/gcc/i486-linux-gnu/4.4.3/libgcc_eh.a(unwind-dw2.o): In function `uw_init_context_1':
(.text+0x22f8): undefined reference to `pthread_once'
Those errors don't come from OpenCV (as one can tell from the function names) but from GLib and libpthread. Use the -lglib-2.0 -lpthread linker flags.