0

first of all sorry for my bad english, then, it look like simple problem, but I tried everything to solve it and nothing work. I have installed OpenCv3.2 and I have build-essential installed correctly.

I link my include and error above.

Include:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/videoio.hpp>

Code that seams to generate the error:

Mat image = Mat::zeros( 1080, 1920, CV_8UC3 );
imshow("Image",image);

Compilation string:

g++ -o FD-progetto-vista-telecamera -O3 -std=gnu++11 -Wall ../FD-super_tracker.cpp -L/usr/local/lib/ -I/usr/local/include/ -lopencv_dnn -lopencv_ml -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_photo -lopencv_imgcodecs -lopencv_video -lopencv_objdetect -lopencv_imgproc -lopencv_flann -lopencv_core -lmysqlclient -lboost_system -lboost_filesystem -lm -ldl -ltiff

Compilation error:

/tmp/cc7wFBb0.o: In function `project(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, Telecamera_coord*, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, Telecamera_coord*> > >)':
FD-super_tracker.cpp:(.text+0xbdd): undefined reference to `cv::String::allocate(unsigned long)'
FD-super_tracker.cpp:(.text+0xbf9): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
FD-super_tracker.cpp:(.text+0xc01): undefined reference to `cv::String::deallocate()'
FD-super_tracker.cpp:(.text+0x1180): undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status

Update:

I also tried with this options (like suggested):

g++ -o FD-progetto-vista-telecamera -O3 -std=gnu++11 -Wall ../FD-super_tracker.cpp -L/usr/local/lib/ -I/usr/local/include/ `pkg-config --libs opencv` -lmysqlclient -lboost_system -lboost_filesystem -lm -ldl -ltiff

And this is the result:

/tmp/ccklBhL2.o: In function `project(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, Telecamera_coord*, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, Telecamera_coord*> > >)':
FD-super_tracker.cpp:(.text+0xbdd): undefined reference to `cv::String::allocate(unsigned long)'
FD-super_tracker.cpp:(.text+0xbf9): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
FD-super_tracker.cpp:(.text+0xc01): undefined reference to `cv::String::deallocate()'
FD-super_tracker.cpp:(.text+0x1180): undefined reference to `cv::String::deallocate()'

----------------------SOLVED----------------------

Thanks everyone for the help, but error occures because i have multiple version of OpenCv installed on my device. I disinstalled all opencv version and then reinstalled it from source. I hope this will be helpfull for someone.

1 Answers1

0

You need to provide the libraries in the proper order. Here, you need to push he library that provides cv::String later (just before opencv_core) in the line.

The linker works by progressively assembling the output, using what is required after each -l, then dropping what isn't. So if later libraries require previous ones, it fails because the linker doesn't loop over the external libs.

As #BjoernUrban said, the proper order is given by pkg-config --libs opencv.

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62