Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking against OpenCV 2.3.1 on Ubuntu

Tags:

c++

opencv

linker

i'm new to OpenCV, and i got a problem with linkage.

I'm using Ubuntu 11.10, OpenCV 2.3.1 was installed according to this guide:

I'm building many small applications with it, and it looks fine. Usually, i'm building with pkg-config --libs --cflags opencv.

Now, i'm trying to build some framework that someone else wrote, it compiles without any problems, but i can't link it: there is a long list of "unresolved reference to..." (thousands of them). all symbols related to opencv_core are not found.

I tried to recompile OpenCV without precompiled header support, didn't help. of course. :(

the test_opencv_core application is running fine, but opencv_rand failed. I think it says that opencv_core is correct, in general, but it still doesn't work when I need it...

Can you please try to give me some hint? I'm lost there.

Thank you in advance, David

Update: Solved.

gcc 4.6.1 require that the libs and sources will apear in the command line before pathes to shared libs. why? don't know. just spent 24 hours for this stupid mistake :(

Update: Understandable. from the ld man page:

The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again.

See the -( option for a way to force the linker to search archives multiple times.

That's it.

like image 798
David Avatar asked Feb 06 '12 07:02

David


People also ask

Where is OpenCV path in Ubuntu?

You can find OpenCV2 (i.e. C++ version) libraries (e.g. libopencv_core.so,libopencv_highgui.so etc) at /usr/local/lib . If you want libraries for c version only (e.g. libcv. a,libcxcore. a etc) you can find them at /usr/lib .

How do I completely remove OpenCV from Ubuntu?

You uninstall using the same tool you used to install. Simply use 'remove' instead of 'install'. Apt does the cleanup -- proper cleanup is a fundamental job of a package manager. You don't need to update your database of available packages in the repository, since you are removing packages instead of installing.


1 Answers

gcc 4.6.1 require that the libs and sources will appear in the command line before paths to shared libs. I don't know why.

Update: Understandable. from the ld man page:

The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again.

See the -( option for a way to force the linker to search archives multiple times.

That's it.

like image 162
Bill the Lizard Avatar answered Sep 18 '22 14:09

Bill the Lizard