OpenCv未定义对`cv ::的引用

时间:2014-10-07 13:43:34

标签: c++ eclipse opencv mingw

我是OpenCv的新手。我正在使用Eclipse C / C ++。当我尝试运行此示例代码时,我遇到了这些错误。我该怎么做才能解决这个问题?配置有什么问题吗?

#using namespace std;
#using namespace cv;

    int main( int argc, const char** argv )
    {
         Mat img = imread("MyPic.JPG", CV_LOAD_IMAGE_UNCHANGED); 
         if (img.empty()) //check whether the image is loaded or not
         {
              cout << "Error : Image cannot be loaded..!!" << endl;
              //system("pause"); //wait for a key press
              return -1;
         }
         namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
         imshow("MyWindow", img); /
         waitKey(0); //wait infinite time for a keypress
         destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"

         return 0;
    }


16:11:28 **** Incremental Build of configuration Debug for project OpenCv ****
Info: Internal Builder is used for build
g++ "-IC:\\opencv\\build\\include" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\OpenCv.o" "..\\src\\OpenCv.cpp" 
g++ "-LC:\\opencv\\build\\x86\\vc12\\lib" -o OpenCv.exe "src\\OpenCv.o" -lopencv_calib3d249 -lopencv_contrib249 -lopencv_core249 -lopencv_features2d249 -lopencv_flann249 -lopencv_gpu249 -lopencv_highgui249 -lopencv_imgproc249 -lopencv_legacy249 -lopencv_ml249 -lopencv_nonfree249 -lopencv_objdetect249 -lopencv_ocl249 -lopencv_photo249 -lopencv_stitching249 -lopencv_superres249 -lopencv_ts249 -lopencv_video249 -lopencv_videostab249 
src\OpenCv.o: In function `main':
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:10: undefined reference to `cv::imread(std::string const&, int)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:19: undefined reference to `cv::namedWindow(std::string const&, int)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:20: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:20: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:22: undefined reference to `cv::waitKey(int)'
C:\Users\ayberk101\workspace\OpenCv\Debug/../src/OpenCv.cpp:24: undefined reference to `cv::destroyWindow(std::string const&)'
src\OpenCv.o: In function `ZN2cv3MatD1Ev':
C:/opencv/build/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
src\OpenCv.o: In function `ZN2cv3Mat7releaseEv':
C:/opencv/build/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'
collect2.exe: error: ld returned 1 exit status

enter image description here

1 个答案:

答案 0 :(得分:2)

问题1:您必须包含opencv / c ++头文件才能使其正常工作:

#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#using namespace cv;

#include <iostream>
#using namespace std;

int main() {
...

然后,问题2:你不能使用mingw的vc12库。 (这是一个不同的编译器)

opencv没有更多prebuild mingw库,因此,在执行其他任何之前,您必须使用cmake 在本地构建 opencv库。


再次,你真的需要使用mingw / eclipse吗? (vs express仍然是免费的)

相关问题