由于未定义的引用而无法编译?
Cannot compile because of undefined references?
我正在绑定 运行 一个简单的 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
未定义的引用错误指的是“无效的库路径”。
确保输入有效的 lib 路径:
他们应该有扩展名“.lib”或“.a”
希望对你有帮助。
已有 similar question 个。尝试添加
-lopencv_imgcodecs
链接器标志列表。
我正在绑定 运行 一个简单的 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
未定义的引用错误指的是“无效的库路径”。 确保输入有效的 lib 路径: 他们应该有扩展名“.lib”或“.a” 希望对你有帮助。
已有 similar question 个。尝试添加
-lopencv_imgcodecs
链接器标志列表。