openCV错误:对`cvLoadImage'Ubuntu的未定义引用

时间:2012-04-10 18:53:51

标签: c++ c opencv ubuntu image-processing

我已经安装了openCV库,但我仍然收到错误
$ g ++ -I / usr / include / opencv / -L -lcxcore -lhighgui hello.cpp -o hello
/tmp/ccjjrbXr.o:在函数main': hello.cpp:(.text+0x2d): undefined reference to cvLoadImage'中 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 个答案:

答案 0 :(得分:13)

您使用单引号'代替backquotes/backticks `。这是更正的命令:

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

答案 1 :(得分:0)

如果你正在使用它,那么链接到highgui lib -lhighgui是个好主意

答案 2 :(得分: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

更容易想象

答案 3 :(得分:-1)

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