Ububtu, opencv and links

I installed Ubuntu a few days ago and used apt-get to install build_essentials, opencv, highgui, etc. g ++ - 4.6.1, opencv - 2.1.0. I did not create opencv from source code ..

We have software that uses opencv functionality. Suppose the source files are called a.cpp and b.cpp. I compile ao and bo files and then put them in the .so library (name it libab.so).

Finally, there is a file with the main one in it (name it z.cpp). I try to create an executable from it, but I get a ton of "undefined links" to cv :: stuff. My link line looks something like this:

g++ -fPIC -g z.cpp -L../lib -lab -lml -lcvaux -lhighgui -lcv -lcxcore -o z.out

then I get undefined help errors (all of which relate to cv :: stuff).

The interesting part is that if I directly contact my .o files, it builds just fine. So:

g++ -fPIC -g z.cpp a.o b.o -lml -lcvaux -lhighgui -lcv -lcxcore -o z.out

works.

Everything I read seems to imply that this is most likely a link binding problem, but I tried all the ordering permutations and got the same problem, so I really don't think this is my problem, but I could still be wrong. Does anyone have any ideas how I can build this with my library, and why will it work differently if I build with a full set of .o files that are in the library successfully but cannot build with the library itself?

+5
source share
2 answers

You can pass the following flag to g ++:

`pkg-config --libs opencv`

For instance:

g++ myprogram.cpp `pkg-config --libs opencv` -o myprogram

pkg-config provide the compiler with library information for you.

:

/usr/local/lib/pkgconfig/opencv.pc

:

prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 2.3.1
Libs: -L${libdir} -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
Cflags: -I${includedir_old} -I${includedir_new}
+12

, C. OpenCV : -lopencv_core -lopencv_flann -lopencv_highgui....

, , ( ).

- EDIT -

-lab opencv libs? , .

+3

All Articles