【发布时间】:2016-05-15 12:41:37
【问题描述】:
在过去的几个小时里,我一直在尝试让一个基本的 OpenCV 程序在我的 Eclipse Mars IDE 中工作。该程序由以下 main.cpp 组成:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
到目前为止我做了什么:
- 已安装 MinGW(在 E:\NVPACK\MinGW)并将其 bin 文件路径添加到我的环境变量中。
在 E:\opencv 安装了 OpenCV 2.4.12。在已安装的文件夹内是“build”和“sources”文件夹。
使用 MinGW GCC 工具链创建了一个新的 Eclipse C++ 项目。
-
在工具设置中(项目属性 --> C/C++ 构建 --> 设置)我将 OpenCV 库作为“E:\opencv\build\include”包含在 GCC C++ 编译器中
在我在 MinGW C++ 链接器中添加的所有库(即 opencv_core2412、opencv_highgui2412、opencv_imgproc2412)的工具设置中,并将库搜索路径设置为“E:\opencv\build\x86\vc12\lib”
将我的二进制解析器设置为 PE Windows 解析器。
构建项目所有OpenCV函数得到未定义引用错误,如:
undefined reference to `cv::imread(std::string const&, int)' main.cpp line 17 C/C++ Problem
undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' main.cpp line 26 C/C++ Problem
很奇怪,声明 Mat 图像不会出错,并且将鼠标悬停在它上面会正确显示 OpenCV 的 Mat 文档。
谷歌搜索问题我发现由于某种原因我可能需要使用 CMake 来构建我自己的库文件(在第 5 步中使用的那些)。所以在安装了 CMake gui 之后,我使用 E:\opencv\sources 作为源目录,并新建了一个目录 E:\opencv\MinGW 作为我的构建目录。我使用“Eclipse CDT4 -MinGW Makefiles”生成器来配置文件。按下配置后,我的 g++ 编译器会收到以下错误(我的 gcc 编译器也有类似的错误):
CMake Error at CMakeLists.txt:71 (project):
The CMAKE_CXX_COMPILER:
E:/NVPACK/MinGW/bin/mingw32-g++
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
但是编译器被标识:“CXX 编译器标识是 GNU 4.8.1”和“C 编译器标识是 GNU 4.8.1”
非常感谢任何有关如何在 Windows 7 上的 Eclipse Mars 中正确设置 OpenCV 2.4.12 库的帮助!
【问题讨论】:
-
您怀疑是什么问题?我已经能够正确构建、编译和运行使用我当前 MinGW 设置的程序。此外,我还测试了另一个使用 OpenCV 旧功能(例如 cvLoadImage 和 cvShowImage)的程序,它实际上可以工作。 *编辑:这是对我的 MinGW 安装可能是问题的评论的回应(但是评论已被删除)。
-
你设置opencv环境变量了吗?见this。此外,您似乎应该将库搜索路径设置为“E:\opencv\build\x86\mingw\lib”(而不是 vc12)。
-
@A.Sarid 是的,我已将其设置为 E:\opencv\build\x86\vc12\bin。还尝试了 E:\opencv\build\x86\vc12 (类似于您的链接),但它给出了相同的结果(当然是在重新启动 Eclipse 之后)。
-
@A.Sarid 设置我的库搜索路径不会做太多,因为我没有那个目录。我尝试自己构建二进制文件,但正如您在我的帖子中看到的那样,我从 CMake 中得到错误。在 vc12 中是链接中描述的预构建二进制文件。我确实认为问题出在这些库文件中,但不知道如何解决 CMake 错误。
标签: c++ eclipse opencv gcc g++