Linking against OpenCV 2.3.1 on Ubuntu-Collection of common programming errors
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.
-
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.
Originally posted 2013-11-06 03:31:03.