0

我在 Ubuntu 12.04 64 位上构建了 opencv。如果我发出以下命令,我可以链接到 opencv 库:

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

但是,如果我发出以下命令:

gcc -g -O2 -W -Wall -Wno-unused -Wno-multichar  -o main main.o -lcxcore -lcv -lhighgui -lcvaux 

我得到:

/usr/bin/ld: cannot find -lcxcore
/usr/bin/ld: cannot find -lcv
/usr/bin/ld: cannot find -lhighgui
/usr/bin/ld: cannot find -lcvaux
collect2: ld returned 1 exit status

要解决我发出的问题:

pkg-config --libs opencv 

并得到:

/usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so

我想这解释了这个问题,但我不明白为什么 opencv.pc 不包含库位置的简写“-llib”格式,如通常的 .pc 文件。有任何想法吗??

4

1 回答 1

0

您需要包含 pkg-config 为您提供的库头文件的位置

pkg-config opencv --cflags

对我来说,输出是

-I/usr/local/include/opencv -I/usr/local/include

如果你添加它,它应该可以正常工作

于 2012-07-12T06:33:28.453 回答