我一直在尝试使用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/
答案 0 :(得分:5)
试试这个:
g++ `pkg-config --cflags opencv` -o hello hello.cpp `pkg-config --libs opencv`
答案 1 :(得分:2)
在您编写此选项的命令中,它会有所不同;该 链接器按顺序搜索和处理库和目标文件 它们是指定的。因此,'foo.o -lz bar.o'之后搜索库'z' 文件foo.o但在bar.o之前如果bar.o引用'z'中的函数, 这些功能可能无法加载。
因此string s
必须位于文件名的末尾,否则gcc将无法解析符号。
DrawString
答案 2 :(得分:0)
参考此主题:
compiling code with OpenCV Libraries
将这些作为命令行参数添加也很有效:
-lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_objdetect