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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10094692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 13:37:50  来源:igfitidea点击:

openCV error : undefined reference to `cvLoadImage' Ubuntu

c++copencvubuntuimage-processing

提问by user1111044

I have installed the openCV libraries but I am still getting the error
$ g++ -I /usr/include/opencv/ -L -lcxcore -lhighgui hello.cpp -o hello
/tmp/ccjjrbXr.o: In function main': hello.cpp:(.text+0x2d): undefined reference tocvLoadImage'
collect2: ld returned 1 exit status

我已经安装了 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 个退出状态

When I check for the path of the libraries I get
$ pkg-config --libs opencv
-lml -lcvaux -lhighgui -lcv -lcxcore

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

I have written a very simple program to test it :

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

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 );
}

There is something wrong with my installation but I am really not able to figure it out. Any guidance will be highly appreciated! Thanks

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



When I run:

当我运行时:

$ 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  

But when I run:

但是当我运行时:

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

OpenCV seems to be installed but still the problem persists.

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

回答by karlphillip

You used single quotes 'instead of backquotes/backticks`. This is the corrected command:

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

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

回答by Martin Beckett

It would be a good idea to link to the highgui lib -lhighguiif you are using it

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

回答by Alexis

this command:

这个命令:

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

is different than this:

与此不同:

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

because of the ` and ' chars...

因为'和'字符......

if you dont want to mess with those chars, you can use

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

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

which is easier to visualize

这更容易形象化

回答by user2652000

try g++ -g -o mypro progname.cpp pkg-config opencv --cflags --libsor

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