Ask Your Question
0

what might cause problems with openCV linking?

asked 2017-01-27 08:59:41 -0600

j0h gravatar image

updated 2017-01-27 09:05:56 -0600

I followed some instructions for installing openCV3, the same ones I usually follow, and it would seem openCV3 is installed. but every program I write returns errors on compiling. The same programs work fine everywhere else i run them. this would be:

 git clone https://github.com/opencv/opencv.git

cd opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j 4
sudo make install
sudo ldconfig

I am on linux, and my compile/ build flags are:

g++ -Wall -g `pkg-config --cflags --libs opencv` -o file file.cpp

I have tried purging, uninstalling, deleting old opencv versions, with reboots, but after installing, and yes, I have run sudo ldconfig when I try to compile, I get this:

 g++ Wall -g `pkg-config --cflags --libs opencv` -o test test.cpp 
/tmp/cchudewP.o: In function `main':
/home/jay/Desktop/test.cpp:7: undefined reference to `cv::imread(cv::String const&, int)'
/home/jay/Desktop/test.cpp:11: undefined reference to `cv::namedWindow(cv::String const&, int)'
/home/jay/Desktop/test.cpp:12: undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
/home/jay/Desktop/test.cpp:13: undefined reference to `cv::waitKey(int)'
/home/jay/Desktop/test.cpp:14: undefined reference to `cv::destroyWindow(cv::String const&)'
/tmp/cchudewP.o: In function `cv::String::String(char const*)':
/usr/local/include/opencv2/core/cvstd.hpp:622: undefined reference to `cv::String::allocate(unsigned long)'
/tmp/cchudewP.o: In function `cv::String::~String()':
/usr/local/include/opencv2/core/cvstd.hpp:664: undefined reference to `cv::String::deallocate()'
/tmp/cchudewP.o: In function `cv::String::operator=(cv::String const&)':
/usr/local/include/opencv2/core/cvstd.hpp:672: undefined reference to `cv::String::deallocate()'
/tmp/cchudewP.o: In function `cv::Mat::~Mat()':
/usr/local/include/opencv2/core/mat.inl.hpp:592: undefined reference to `cv::fastFree(void*)'
/tmp/cchudewP.o: In function `cv::Mat::release()':
/usr/local/include/opencv2/core/mat.inl.hpp:704: undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status

basically, every call to anything openCV fails.

I have looked for the opencv libraries, and they are in the appropriate place:

ls  -al /usr/local/include/opencv2/*.hpp 
-rw-r--r-- 1 root root  27236 Jan 26 20:12 /usr/local/include/opencv2/aruco.hpp
-rw-r--r-- 1 root root   7518 Jan 26 20:12 /usr/local/include/opencv2/bgsegm.hpp
...

They are there.

I have tried all the things I know how to do, and I get the same issue every-time. I am on Ubuntu, if anyone can help me get oopencv installed so I can compile programs, I would be grateful.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-01-27 09:56:26 -0600

berak gravatar image

if pkg-config fails for you, you could still try to:

  • use cmake to generate a makefile
  • or just write one manually:

    g++ my.cpp -I.-I/usr/local/include -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui -o myprog

edit flag offensive delete link more

Comments

To summarise those options: g++ [source file name(s) .cpp] -o [output file name] -I[path to library's header directory; for the compiler] -L[path to pre-compiled library's directory; for the linker] -l[pre-compiled library's name; for the linker]

WillC gravatar imageWillC ( 2018-11-10 21:01:21 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-27 08:59:41 -0600

Seen: 5,677 times

Last updated: Jan 27 '17