gpt4 book ai didi

c++ - openCV 错误 : undefined reference to `cvLoadImage' Ubuntu

转载 作者:可可西里 更新时间:2023-11-01 17:35:42 25 4
gpt4 key购买 nike

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

最佳答案

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

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

关于c++ - openCV 错误 : undefined reference to `cvLoadImage' Ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10094692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com