gpt4 book ai didi

image - 无法编译第一个 opencv 程序, '/usr/bin/ld: cannot find -lcv'

转载 作者:太空宇宙 更新时间:2023-11-03 20:51:54 25 4
gpt4 key购买 nike

g++ cv.cpp -o cv -I /usr/local/include/opencv
-L /usr/local/lib -lm -lcv -lhighgui -lcvaux

错误:

/usr/bin/ld: cannot find -lcv
collect2: ld returned 1 exit status

代码:

#include <cv.h>
#include <ml.h>
#include <cxcore.h>
//#include <cxtypes.h>
#include <highgui.h>

int main(int argc, char* argv[])
{
IplImage* img = cvLoadImage( "bal.png" );
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage("Example1", img);
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
return 0;
}

它是 32 位的,

locate libcv
/usr/lib/libcv.so.2.1
/usr/lib/libcv.so.2.1.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

在/usr/local下安装了OpenCV-2.4.0,我也有一个系统python-opencv。我在哪里做错了?我该怎么办?

最佳答案

changelog 可以看出在 OpenCV 网站上发布(2.2 版本),库名称从 2.2 版本开始发生了变化,因此用于链接 2.1 版本的库名称不能用于与 2.4 版本编译(即 libcv.so 通过 -lcv 链接的库名称对于版本 > 2.1 等来说是无效的)。您需要传递作为新版本 OpenCV 一部分的库(已通过 pkg-config 命令列出)。您可以使用 pkg-config 在这些行上传递编译器和链接器标志:g++ cv.cpp -o cv $(pkg-config --cflags --libs opencv)
希望这对您有所帮助!

关于image - 无法编译第一个 opencv 程序, '/usr/bin/ld: cannot find -lcv',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10452801/

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