我在 linux 中尝试使用 g++ 编译 opencv 的一些示例代码时遇到了麻烦,但是在运行后我收到了以下错误消息:
g++ `pkg-config --cflags --libs opencv` hello.cpp -o hello
我得到这个输出:
/tmp/ccjvVxLI.o: In function `main':
hello.cpp:(.text+0x45): undefined reference to `cvLoadImage'
hello.cpp:(.text+0x6b): undefined reference to `cvNamedWindow'
hello.cpp:(.text+0x7c): undefined reference to `cvShowImage'
hello.cpp:(.text+0x86): undefined reference to `cvWaitKey'
hello.cpp:(.text+0x90): undefined reference to `cvDestroyWindow'
collect2: ld returned 1 exit status
我在网上查看并检查了我的 OpenCV 安装,我得到了以下的正常输出:
pkg-config --cflags opencv
作为:
-I/usr/local/include/opencv -I/usr/local/include
但是当我跑的时候:
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
如果有帮助,我在本网站的帮助下在 ubuntu LTS 12.04 上安装了 Opencv2.4.1:http: //www.samontab.com/web/2012/06/installing-opencv-2-4-1-ubuntu-12-04 -lts/