仅在使用各种包含时获取未定义的引用

时间:2018-03-30 18:31:49

标签: c++ opencv mingw

我遇到运行此代码的问题:

    // CannyStill.cpp

    //#include "opencv2/core/core.hpp"
    #include "opencv2/highgui/highgui.hpp"
    #include "opencv2/imgproc/imgproc.hpp"

    #include<iostream>
    #include<conio.h>        

int main() {
  cv::Mat imgOriginal;        // input image
  cv::Mat imgGrayscale;       // grayscale of input image
  cv::Mat imgBlurred;         // intermediate blured image
  cv::Mat imgCanny;           // Canny edge image

  imgOriginal = cv::imread("image.png");          // open image

if (imgOriginal.empty()) {                                  // if unable to open image
    std::cout << "error: image not read from file\n\n";     // show error message on command line
    _getch();                                               // may have to modify this line if not using Windows
    return(0);                                              // and exit program
}

cv::cvtColor(imgOriginal, imgGrayscale, CV_BGR2GRAY);       // convert to grayscale

cv::GaussianBlur(imgGrayscale,          // input image
    imgBlurred,                         // output image
    cv::Size(5, 5),                     // smoothing window width and height in pixels
    1.5);                               // sigma value, determines how much the image will be blurred

cv::Canny(imgBlurred,           // input image
    imgCanny,                   // output image
    82,                         // low threshold
    164);                       // high threshold

                                // declare windows
cv::namedWindow("imgOriginal", CV_WINDOW_AUTOSIZE);     // note: you can use CV_WINDOW_NORMAL which allows resizing the window
cv::namedWindow("imgCanny", CV_WINDOW_AUTOSIZE);        // or CV_WINDOW_AUTOSIZE for a fixed size window matching the resolution of the image
                                                        // CV_WINDOW_AUTOSIZE is the default
cv::imshow("imgOriginal", imgOriginal);     // show windows
cv::imshow("imgCanny", imgCanny);

cv::waitKey(0);                 // hold windows open until user presses a key

return(0);

}

我的问题似乎来自include语句中的问题。我可以在其中的一两个中得到所有包含的内容:

C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x81): undefined reference to `cv::imread(cv::String const&, int)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0xd4): undefined reference to `std::cout'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0xd9): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x142): undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x1e1): undefined reference to `cv::GaussianBlur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x25a): undefined reference to `cv::Canny(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, bool)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x295): undefined reference to `cv::namedWindow(cv::String const&, int)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x2c6): undefined reference to `cv::namedWindow(cv::String const&, int)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x30c): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x35c): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x37c): undefined reference to `cv::waitKey(int)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x4e3): undefined reference to `std::ios_base::Init::~Init()'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text+0x504): undefined reference to `std::ios_base::Init::Init()'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text$_ZN2cv6StringC1EPKc[__ZN2cv6StringC1EPKc]+0x42): undefined reference to `cv::String::allocate(unsigned int)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text$_ZN2cv6StringD1Ev[__ZN2cv6StringD1Ev]+0xf): undefined reference to `cv::String::deallocate()'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x2d): undefined reference to `cv::fastFree(void*)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text$_ZN2cv3Mat7releaseEv[__ZN2cv3Mat7releaseEv]+0x40): undefined reference to `cv::Mat::deallocate()'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.text$_ZN2cv3MataSEOS0_[__ZN2cv3MataSEOS0_]+0xb4): undefined reference to `cv::fastFree(void*)'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.eh_frame$_ZN2cv6StringD1Ev+0x13): undefined reference to `__gxx_personality_v0'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.eh_frame$_ZN2cv3MatD1Ev+0x13): undefined reference to `__gxx_personality_v0'
C:\Users\RYANDE~1\AppData\Local\Temp\cceJbRuT.o:CannyStill.cpp:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0'
collect2.exe: error: ld returned 1 exit status

我一直在评论一些并包括其他人,它只是留下了一个错误,cv没有一些功能。根据我对opencv的理解,我需要所有这些库。

我正在使用OpenCV 3.4.1,我是使用Cmake for MinGW编译器从源代码构建的,我试图用它来编译它。

任何帮助将不胜感激,如果您有任何疑问,我会尽力回答他们。感谢。

0 个答案:

没有答案