我在 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 文件。有任何想法吗??