2012-03-26 115 views
8

我跟了這tutorial這裏正好提到OpenCV的構建於Visual Studio的鏈接錯誤

我現在嘗試在Visual Studio中運行簡單的OpenCV的代碼,但我不斷收到鏈接錯誤。 我想這OpenCV的tutorial in particular

這裏是我不斷收到錯誤:

1>Linking... 
1>LINK : warning LNK4067: ambiguous entry point; selected 'mainCRTStartup' 
1>OpenCV_Proj.obj : error LNK2019: unresolved external symbol "int __cdecl cv::waitKey(int)" ([email protected]@@[email protected]) referenced in function _main 
1>OpenCV_Proj.obj : error LNK2019: unresolved external symbol "void __cdecl cv::imshow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::_InputArray const &)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z) referenced in function _main 
1>OpenCV_Proj.obj : error LNK2019: unresolved external symbol "public: __thiscall cv::_InputArray::_InputArray(class cv::Mat const &)" ([email protected]@@[email protected]@[email protected]@Z) referenced in function _main 
1>OpenCV_Proj.obj : error LNK2019: unresolved external symbol "void __cdecl cv::namedWindow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) referenced in function _main 
1>OpenCV_Proj.obj : error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" ([email protected]@@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) referenced in function _main 
1>OpenCV_Proj.obj : error LNK2019: unresolved external symbol "void __cdecl cv::fastFree(void *)" ([email protected]@@[email protected]) referenced in function "public: __thiscall cv::Mat::~Mat(void)" ([email protected]@@[email protected]) 
1>OpenCV_Proj.obj : error LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::copySize(class cv::Mat const &)" ([email protected]@[email protected]@[email protected]@Z) referenced in function "public: class cv::Mat & __thiscall cv::Mat::operator=(class cv::Mat const &)" ([email protected]@@[email protected]@@Z) 
1>OpenCV_Proj.obj : error LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::deallocate(void)" ([email protected]@[email protected]@QAEXXZ) referenced in function "public: void __thiscall cv::Mat::release(void)" ([email protected]@[email protected]@QAEXXZ) 
1>C:\Users\Saher\Documents\Visual Studio 2008\Projects\OpenCV_Proj\Debug\OpenCV_Proj.exe : fatal error LNK1120: 8 unresolved externals`` 

對於下面的代碼:

// OpenCV_Proj.cpp : Defines the entry point for the console application. 

//

#include "stdafx.h" 
#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", CV_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; 
} 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
    return 0; 
} 

我一直試圖讓OpenCV在VS2008上工作一段時間並獲得任何幫助這個問題將會受到重視。

注:在本教程下面的自述文件是什麼我也跟着:

1) Add build\bin and one of build\{x86|x64}\{vc9\vc10\mingw}\bin to your system path (to use DLLs) 
    Add build\{x86|x64}\{vc9\vc10\mingw}\lib or 
     build\{x86|x64}\{vc9\vc10\mingw}\staticlib as library directories to your linker settings, 
    Add build\include and build\include\opencv as include directories to your compiler settings. 



Any help with getting this to work is really appreciated. 

回答

8

這些符號OpenCV的庫中定義的,所以您需要配置項目,並讓連接器知道的OpenCV您正在使用的庫。

在你應該添加最起碼的:opencv_core230.libopencv_highgui230.lib(對於OpenCV的2.3.0)

有關如何做到這一點的VS2010,check this tutorial更多信息。

+0

謝謝。解決了鏈接器問題 – 2012-03-26 18:56:36

+0

嗨,我有一個問題... 如果我們使用CMake構建VS2010項目,它是否不會創建所有依賴關係...?我仍然得到相同的錯誤 – user1036908 2013-01-28 06:38:57

2

轉到屬性 - >連接器 - >輸入和

添加cv210.lib; cxcore210.lib; highgui210.lib; cvaux210.lib;

您的問題將得到解決。

有一個快樂的編碼....

+0

謝謝你解決了連接器問題。 – 2012-03-26 18:56:20