我想要运行一个简单的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;
}
这是日食输出:基本上它说: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
答案 0 :(得分:1)
未定义的引用错误引用“无效的lib路径”。 确保输入有效的lib路径: 他们应该有扩展名“.lib”或“.a” 希望它有所帮助。
答案 1 :(得分:1)