8

我已经安装了 openCV 库,但仍然收到错误
$ g++ -I /usr/include/opencv/ -L -lcxcore -lhighgui hello.cpp -o hello
/tmp/ccjjrbXr.o: In function cvLoadImage main': hello.cpp:(.text+0x2d): undefined reference to'
collect2: ld返回 1 个退出状态

当我检查库的路径时,我得到
$ pkg-config --libs opencv
-lml -lcvaux -lhighgui -lcv -lcxcore

我写了一个非常简单的程序来测试它:

enter code here

#include< cv.h>  
#include< highgui.h> /* required to use OpenCV's highgui */
#include< stdio.h>

int main() { 
    IplImage* img = 0;
    printf("Hello\n");
    img = cvLoadImage("lena.jpg", 0 );
}

我的安装有问题,但我真的无法弄清楚。任何指导将不胜感激!谢谢


当我运行时:

$ pkg-config --cflags --libs opencv
-I/usr/local/include/opencv -I/usr/local/include
/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  

但是当我运行时:

$ g++ 'pkg-config --cflags --libs opencv' display_image.cpp
g++: error: pkg-config --cflags --libs opencv: No such file or directory

OpenCV 似乎已安装,但问题仍然存在。

4

4 回答 4

15

您使用了单引号'而不是反引号/反引号 `。这是更正后的命令:

g++ hello.cpp -o hello `pkg-config --cflags --libs opencv` 
于 2012-04-11T04:22:29.333 回答
0

这个命令:

g++ 'pkg-config --cflags --libs opencv' display_image.cpp

与此不同:

g++ `pkg-config --cflags --libs opencv` display_image.cpp

因为 ` 和 ' 字符...

如果你不想弄乱这些字符,你可以使用

g++ $(pkg-config --cflags --libs opencv) display_image.cpp

哪个更容易可视化

于 2013-12-01T19:42:30.627 回答
0

-lhighgui如果您正在使用它,最好链接到 highgui 库

于 2012-04-10T18:58:36.557 回答
-1

尝试 g++ -g -o mypro progname.cpppkg-config opencv --cflags --libs

于 2013-08-27T09:39:50.940 回答