gpt4 book ai didi

c++ - 由于 undefined reference 而无法编译?

转载 作者:行者123 更新时间:2023-11-28 02:29:24 25 4
gpt4 key购买 nike

我想运行一个简单的 OpenCV 代码,但不幸的是我遇到了一个undefined reference 错误。我真的不知道该怎么办。这是我试图让它运行的代码

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main(int argc, char** argv) {

Mat image;

image = imread(argv[1], 1);
//...
return 0;
}

这是 eclipse 输出:基本上它说:undefined reference to cv::imread(cv::String const&, int)'

完整的错误信息是:

g++ -L/usr/local/lib -o "TestOpenCV"  ./src/TestOpenCV.o   -lopencv_core -lopencv_highgui
./src/TestOpenCV.o: In function `main':
/media/cip/Media/workspace/OpenCV/TestOpenCV/Debug/../src/TestOpenCV.cpp:21: undefined reference to cv::imread(cv::String const&, int) collect2: error: ld returned 1 exit status make: *** [TestOpenCV] Error 1

pkg-config opencv --libs 的列表输出如下所示:

/usr/local/lib/libopencv_calib3d.so 
/usr/local/lib/libopencv_core.so
/usr/local/lib/libopencv_features2d.so
/usr/local/lib/libopencv_flann.so
/usr/local/lib/libopencv_highgui.so
/usr/local/lib/libopencv_imgcodecs.so
/usr/local/lib/libopencv_imgproc.so
/usr/local/lib/libopencv_ml.so
/usr/local/lib/libopencv_objdetect.so
/usr/local/lib/libopencv_photo.so
/usr/local/lib/libopencv_shape.so
/usr/local/lib/libopencv_stitching.so
/usr/local/lib/libopencv_superres.so
/usr/local/lib/libopencv_ts.a
/usr/local/lib/libopencv_video.so
/usr/local/lib/libopencv_videoio.so
/usr/local/lib/libopencv_videostab.so
/usr/local/lib/libopencv_viz.so

最佳答案

undefined reference 错误指的是“无效的库路径”。确保输入有效的 lib 路径: 他们应该有扩展名“.lib”或“.a”希望对您有所帮助。

关于c++ - 由于 undefined reference 而无法编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29416011/

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