2016-05-26 108 views
0

我想用mingw-w64编译下面的代码。用mingw编译opencv3.1

#include <iostream> 
#include <opencv2/core.hpp> 
#include <opencv2/highgui.hpp> 
#include <opencv2/opencv.hpp> 
using namespace cv; 
using namespace std; 

int main(int argc, char** argv) 
{ 
    Mat im = imread("lena.jpg", 1); 
    if (im.empty()) 
    { 
    cout << "Cannot open image!" << endl; 
    return -1; 
    } 

    imshow("image", im); 
    waitKey(0); 

    return 0; 
} 

以下Getting started with OpenCV 2.4 and MinGW on Windows 7

后,我编译g++ -I D:\opencv\build\include -L D:\opencv\build\x64\vc14\lib -lopencv_world310 .\loadimg.cpp

的代码,但它返回undefined参考

C:\Users\1409021\AppData\Local\Temp\cc8ZRPJP.o:loadimg.cpp:(.text+0x40): undefined reference to `cv::imread(cv::String const&, int)' 
C:\Users\1409021\AppData\Local\Temp\cc8ZRPJP.o:loadimg.cpp:(.text+0xb7): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)' 
C:\Users\1409021\AppData\Local\Temp\cc8ZRPJP.o:loadimg.cpp:(.text+0xd9): undefined reference to `cv::waitKey(int)' 
C:\Users\1409021\AppData\Local\Temp\cc8ZRPJP.o:loadimg.cpp:(.text$_ZN2cv6StringC1EPKc[_ZN2cv6StringC1EPKc]+0x4a): undefined reference to `cv::String::allocate(unsigned long long)' 
C:\Users\1409021\AppData\Local\Temp\cc8ZRPJP.o:loadimg.cpp:(.text$_ZN2cv6StringD1Ev[_ZN2cv6StringD1Ev]+0x11): undefined reference to `cv::String::deallocate()' 
C:\Users\1409021\AppData\Local\Temp\cc8ZRPJP.o:loadimg.cpp:(.text$_ZN2cv3MatD1Ev[_ZN2cv3MatD1Ev]+0x36): undefined reference to `cv::fastFree(void*)' 
C:\Users\1409021\AppData\Local\Temp\cc8ZRPJP.o:loadimg.cpp:(.text$_ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x48): undefined reference to `cv::Mat::deallocate()' 

库是opencv3.1,并且只有一个库opencv_world310

有何建议?

谢谢。

回答

0
g++ -I D:\opencv\build\include -L D:\opencv\build\x64\vc14\lib -lopencv_world310 .\loadimg.cpp 

是错误的。

g++ -I D:\opencv\build\include -L D:\opencv\build\x64\vc14\lib .\loadimg.cpp -lopencv_world310 

是对的。解释here