我需要帮助。 几个月前,我在 Windows 上的 Visual Studio 中编写了这段 C++ 代码。我从该代码制作 .exe 文件,一切正常,就像这样。这是用于图像处理的简单代码。现在我尝试在 Linux 上的 Eclipse 中做同样的事情,以便我可以将可执行文件放在 Linux Web 服务器上。但是我有这个错误:
In function `main':
main.cpp:(.text.startup+0x317): undefined reference to `cv::inpaint(cv::_InputArray const&, cv::_InputArray const&, cv::_OutputArray const&, double, int)'
collect2: ld returned 1 exit status
make: *** [inpaint] Error 1
我使用 OpencCV 2.4.1 库。这是源代码:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/photo/photo.hpp"
#include <iostream>
using namespace cv;
using namespace std;
Mat img, img0, maska;
int main( int argc, char** argv )
{
...
}
Mat inpainted;
inpaint(img0, img, inpainted, 2, CV_INPAINT_NS);
char imeobr[256] = "images/img-uploads/finish";
strcat( imeobr, argv[1] );
strcat( imeobr, ".jpg" );
imwrite(imeobr, inpainted);
return 0;
}
我认为这是输入源的问题,因为它不是输入图像的固定名称。但是,我需要为每个应用程序用户动态更改输入源。 请帮助人们。我能做什么?
最佳答案
当您忽略链接库时会发生 undefined reference 错误:
在您的项目的首选项中:
C/C++ Build -> GCC C++ Linker -> Libraries
你有没有在 Libraries(-l) 中输入 libopencv_imgproc 库?
更新
为了测试,我创建了我的程序:
#include <opencv/highgui.h>
#include <opencv/cv.h>
using namespace cv;
int main(int argc, char* argv[]) {
Mat img, img0;
Mat inpainted;
inpaint(img0, img, inpainted, 2, CV_INPAINT_NS);
}
在我链接的库中:
opencv_imgproc
opencv_highgui
opencv_core
一切正常..试一试然后告诉我!
关于c++ - 对 cv::inpaint 的 undefined reference - 错误 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13741143/