2015-10-13 77 views
2

問題固定用OpenCV的混合STL實現

我試圖讓OpenCV的啓動和運行,但我遇到了同樣的問題this guythis guy - 試圖建立與該項目時,我得到鏈接錯誤C++接口,但使用C接口項目構建。

在第二個鏈接中,答案是「您正在混合STL.VC10(用於OpenCV)和STLPort(用於您的代碼)的不同實現。」

如何確保我只使用VC10? (或更高版本)

空調風格(項目成功生成)

我使用Visual Studio 2012和OpenCV 3.0

int main(int argc, char** argv) 
{ 
    char* filename = "input.tif"; 
    IplImage *img0; 

    if((img0 = cvLoadImage(filename,-1)) == 0) 
     return 0; 

    cvNamedWindow("image", 0); 
    cvShowImage("image", img0); 
    cvWaitKey(0); 
    cvDestroyWindow("image"); 
    cvReleaseImage(&img0); 
} 

C++風格(項目不建)

int main(int argc, char** argv) { 

    Mat image; 
    const string &filename = "input.tif"; 
    image = imread(filename, IMREAD_COLOR); // Read the file 

    if(! image.data) // Check for invalid input 
    { 
     std::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. 
} 

錯誤:

1>Source.obj : error LNK2019: unresolved external symbol "private: char * __thiscall cv::String::allocate(unsigned int)" ([email protected]@[email protected]@[email protected]) referenced in function "public: __thiscall cv::String::String(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" ([email protected]@@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) 
1>Source.obj : error LNK2019: unresolved external symbol "private: void __thiscall cv::String::deallocate(void)" ([email protected]@[email protected]@AAEXXZ) referenced in function "public: __thiscall cv::String::~String(void)" ([email protected]@@[email protected]) 
1>Source.obj : error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class cv::String const &,int)" ([email protected]@@[email protected]@[email protected]@[email protected]) referenced in function _main 
1>Source.obj : error LNK2019: unresolved external symbol "void __cdecl cv::namedWindow(class cv::String const &,int)" ([email protected]@@[email protected]@[email protected]) referenced in function _main 
1>Source.obj : error LNK2019: unresolved external symbol "void __cdecl cv::imshow(class cv::String const &,class cv::_InputArray const &)" ([email protected]@@[email protected]@[email protected]@@Z) referenced in function _main 

包含和在VS庫路徑設置

  • C/C++ /普通/附加包含目錄: C:\的OpenCV \建立\包括
  • 鏈接器/普通/其他庫目錄: \ n C:\ opencv \ build \ x86 \ vc11 \ lib
  • 鏈接器/輸入/附加依賴: opencv_calib3d2410d.lib opencv_contrib2410d.lib opencv_core2410d.lib opencv_features2d2410d.lib opencv_flann2410d.lib opencv_gpu2410d.lib opencv_highgui2410d.lib opencv_imgproc2410d.lib opencv_legacy2410d.lib opencv_ml2410d.lib opencv_nonfree2410d.lib opencv_objdetect2410d.lib opencv_ocl2410d.lib opencv_photo2410d.lib opencv_stitching2410d.lib opencv_superres2410d.lib opencv_ts2410d.lib opencv_video2410d.lib opencv_videostab2410d.lib
+0

你可以顯示你的'#include'嗎?和你的圖書館路徑? – Miki

+0

我添加了我對解決方案屬性所做的更改 – Attaque

+0

@Attaque我非常確定您不是指[tag:stl],而是移除了標記。請在下次添加標籤之前閱讀標籤wiki。你也應該改變你的問題中的文字,而不是引用C++標準庫。 –

回答

1

在聊天討論,事實證明,在OP被鏈接到的OpenCV的2.4.10,而不是OpenCV的3.0。

通過更正鏈接庫,問題得以解決。

+0

謝謝你的幫助。 – Attaque