2013-08-21 5 views
14

이 간단한 프로그램을 작성하여 txt 파일에서 행렬을로드하고 거리를 계산합니다. 창문에서 Visual Studio에서 프로그램을 컴파일 할 때 나는 다음과 같은 오류를 얻을 :오류 LNK2019 : 해결되지 않은 외부 기호 opencv

1>main.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>system.obj : error LNK2001: unresolved external symbol "void __cdecl cv::fastFree(void *)" ([email protected]@@[email protected]) 
1>main.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>system.obj : error LNK2001: unresolved external symbol "public: void __thiscall cv::Mat::deallocate(void)" ([email protected]@[email protected]@QAEXXZ) 
1>main.obj : error LNK2019: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" ([email protected]@@[email protected]) referenced in function "public: void __thiscall cv::Mat::release(void)" ([email protected]@[email protected]@QAEXXZ) 
1>system.obj : error LNK2001: unresolved external symbol "int __cdecl cv::_interlockedExchangeAdd(int *,int)" ([email protected]@@[email protected]) 
1>system.obj : error LNK2019: unresolved external symbol "public: __thiscall cv::Exception::Exception(int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,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 "public: int & __thiscall cv::Mat::at<int>(int,int)" ([email protected]@[email protected]@@[email protected]) 
1>system.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall cv::Exception::~Exception(void)" ([email protected]@@[email protected]) referenced in function "public: int & __thiscall cv::Mat::at<int>(int,int)" ([email protected]@[email protected]@@[email protected]) 
1>system.obj : error LNK2019: unresolved external symbol "void __cdecl cv::error(class cv::Exception const &)" ([email protected]@@[email protected]@@Z) referenced in function "public: int & __thiscall cv::Mat::at<int>(int,int)" ([email protected]@[email protected]@@[email protected]) 
1>system.obj : error LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::create(int,int const *,int)" ([email protected]@[email protected]@[email protected]) referenced in function "public: void __thiscall cv::Mat::create(int,int,int)" ([email protected]@[email protected]@[email protected]) 
1>C:\Users\Ram\documents\visual studio 2012\Projects\descrip\Debug\descrip.exe : fatal error LNK1120: 7 unresolved externals 

는 내 컴퓨터에서 OpenCV의 2.4.6을 intsalled 제대로 비주얼 스튜디오에 연결. 내가 뭘 잘못

MAIN.CPP

#include "system.h" 

using namespace std; 

int main(int argc, char* argv[]){  
    if(argc != 3){ 
    cout << "Not enough arguments" << endl; 
    exit(-1); 
    } 

    System s(argv[2]); 
    s.Parse_Centers(argv[1]); 
    s.Run(); 
    return 0; 
} 

system.h

#include <iostream> 
#include <fstream> 
#include <dirent.h> 
#include <time.h> 
#include "cv.h" 
#include "highgui.h" 
#include "opencv2/opencv.hpp" 

#define NUM_CENTERS 5000 
#define NUM_COL 512 

using namespace cv; 

class System{ 
public: 
    System(char *dir); 
    void Run(); 
    void Parse_Centers(char* path); 
    void Compute_Histogram(const char* filename); 

private: 
    Mat centers; 
    Mat centers_zero; 
    char *dir_path; 
}; 

system.cpp

#include "system.h" 

using namespace std; 
using namespace cv; 

System::System(char *dir){ 
    centers.create(NUM_CENTERS, NUM_COL, CV_8U); 
    centers_zero.create(NUM_CENTERS, NUM_COL, CV_8U); 
    dir_path = dir; 
}; 

void System::Parse_Centers(char* path){ 
    ifstream fin; 
    int temp, n, line = 0; 
    fin.open(path); 

    if(!fin.good()){ 
     throw 1; 
    } 

    while(!fin.eof()){ 
     char buf[2048]; 
     const char* token[NUM_COL] = {}; 

     n = 0; 
     fin.getline(buf, 2048); 
     token[0] = strtok(buf, ","); 

     if(token[0]){ 
      temp = atoi(token[0]); 
      if(temp){ 
       centers.at<int>(line,n) = temp; 
       centers_zero.at<int>(line,n) = temp * temp; 
      } 

      for(int n = 1; n < 512; n++){ 
       token[n] = strtok(0, ","); 
       temp = atoi(token[n]); 
       if(temp){ 
        centers.at<int>(line,n) = temp; 
        centers_zero.at<int>(line,n) = temp * temp; 
       } 
      } 
     } 
     line++; 
    } 

    fin.close(); 
}; 

void System::Run(){ 
    DIR *dir; 
    struct dirent *entry; 
    time_t start_t; 
    time_t end_t; 

    dir = opendir(dir_path); 
    if(!dir){ 
     cout << "Directory wasn't found" << endl; 
     throw 3; 
    } 

    while((entry = readdir(dir)) != NULL){ 
     if(entry->d_name[0] != '.'){ 
      string path = string(dir_path) + "/" + string(entry->d_name); 
      cout << "entry: " << path; 
      time(&start_t); 
      Compute_Histogram(path.c_str()); 
      time(&end_t); 
      cout << " " << difftime(start_t,end_t) << "sec" << endl; 
     } 
    } 

    closedir(dir); 
} 

void System::Compute_Histogram(const char* filename){ 
    int dist[NUM_CENTERS]; 
    int desc[NUM_CENTERS] = {0}; 
    int temp, place = 0; 

    ifstream fin; 
    fin.open(filename); 

    if(!fin.good()){ 
     throw 2; 
    } 

    while(!fin.eof()){ 
     char buf[2048]; 
     const char* token[512] = {}; 

     fin.getline(buf, 2048); 
     token[0] = strtok(buf, ","); 
     if(token[0]){ 
      temp = atoi(token[0]); 
      if(temp){ 
       for(int i = 0; i < NUM_CENTERS; i++){ 
        dist[i] = (temp - centers.at<int>(i,0)) * (temp - centers.at<int>(i,0)); 
       } 
      } 
      else{ 
       for(int i = 0; i < NUM_CENTERS; i++){ 
        dist[i] = centers_zero.at<int>(i,0); 
       } 
      } 

      for(int n = 1; n < NUM_COL; n++){ 
       token[n] = strtok(0, ","); 
       temp = atoi(token[n]); 

       if(temp){ 
        for(int i = 0; i < NUM_CENTERS; i++){ 
         dist[i] += (temp - centers.at<int>(i,n)) * (temp - centers.at<int>(i,n)); 
         if((n == 511) && (i > 0)){ 
          if(dist[i] < dist[place]){ 
           place = i; 
          } 
         } 
        } 
       } 
       else{ 
        for(int i = 0; i < NUM_CENTERS; i++){ 
         dist[i] += centers_zero.at<int>(i,n); 
         if((n == 511) && (i > 0)){ 
          if(dist[i] < dist[place]){ 
           place = i; 
          } 
         } 
        } 
       } 
      } 
     } 

     desc[place]++; 
    } 

    fin.close(); 

    ofstream outfile; 
    string path; 
    path = string(filename) + ".csv"; 
    outfile.open(path.c_str()); 
    for(int i = 0; i < 4999; i++){ 
     outfile << desc[i] << ","; 
    } 
    outfile << desc[4999]; 
    outfile.close(); 
}; 

????

+1

CV 라이브러리가 프로젝트에 제대로 연결되지 않은 것으로 보입니다. –

+1

그러면 LNK2019가 덤프 시간에 다시 튀어 오릅니다. :-D – Abhineet

+1

나는 비슷한 경험을하고 있습니다. 동일한 누락 된 기호 (예외 및 interlockedExchangeAdd)가 나타납니다. opencv 라이브러리를 제거하면 더 많은 누락 된 심볼이 생기지 만 모두 추가되면 이러한 특정 심볼은 여전히 ​​누락됩니다. 여기에 뭔가가있어. –

답변

1

아마도 올바른 헤더 파일을 포함했지만 라이브러리를 추가하는 것을 잊었을 것입니다. 해당 * .lib 파일을 프로젝트 설정에 추가해야합니다.

+1

C : \ OpenCV \ build \ include \ opencv를 추가하여 디렉토리를 포함 시켰습니다. 및 C : \ OpenCV \ build \ x64 \ vc11 \ lib를 라이브러리 디렉토리에 추가하고 opencv_ .lib을 사용하여 링커의 추가 종속성을 확인합니다. 더하기 내 컴퓨터 경로 변수는 C : \ OpenCV \ build \ x64 \ vc11 \ bin dll 디렉토리를 가리 킵니다. 또 뭐야? – RamBracha

+0

opencv_core246.lib (또는 거기에있는 버전) 누락에 대한 모든 메시지 힌트 – berak

+0

Visual Studio에서 OpenCV를 설정하는 데 사용한 자습서는 무엇입니까? 경로 변수를 "\ bin"없이 C : \ OpenCV \ build \ x64 \ vc10 \으로 편집해야합니다. 또한 Visual Studio 2010에서는 vc11 대신 vc10 폴더를 사용해야합니다. – OpenMinded

17

다른 언급했듯이 OpenCV 라이브러리에 올바르게 연결되어 있는지 확인해야합니다. > 속성 - -> VC++ 디렉터리 - 당신의 프로젝트

확인> 라이브러리 디렉토리에서, OpenCV의 라이브러리가있는 경로가 포함이 기본값은 'C : \ OpenCV의 \ \ 86 \ VC11의 \ lib 디렉토리를 구축'이 될 것이다 (VS2012를 실행하는 32 비트 컴퓨터에서는 다른 설정에 따라 달라집니다.

다음, 다음과 같은 라이브러리는 당신의 프로젝트에 포함되어 있는지 확인 -> 속성 -> 링커 -> 입력 -> 추가 종속성 :

opencv_core246d.lib
opencv_imgproc246d.lib
opencv_highgui246d. LIB

opencv_video246d.lib opencv_ml246d.lib

opencv_cal opencv_features2d246d.lib 위의이 올바른 경우 ib3d246d.lib

opencv_flann246d.lib
opencv_legacy246d.lib
opencv_contrib246d.lib
opencv_objdetect246d.lib, 당신은 더 이상 OpenCV의 링크 에러가 발생하지 않아야합니다.

+0

이것은 나를 위해 일했다 .. 감사합니다 – Hetal

+0

나를 위해 작동하지 않았다, 나는 여전히 같은 오류가 발생하고 있습니다. –

+0

[이것은 현재 구식 일 것입니다] (http://answers.opencv.org/question/122936/library-to-link-for-imread/), opencv 3.4.1의 바이너리 배포판에서 얻을 수있는 유일한 lib는 다음과 같습니다. opencv_world341d.lib. – jrh

9

아마 당신은 win32 용이지만 x64 용으로 구축하고있을 것입니다. 응용 프로그램을 x64로 설정하면 빌드가되지만 win32에서는 연결 오류가 발생합니다. 솔루션을 마우스 오른쪽 단추로 클릭하고 구성, 플랫폼 열로 이동하십시오. 나는 이것을 설정하는 것이 까다로웠다. 버그인지 아닌지 궁금하다.

+1

이것은 나를 위해 일했습니다. 고마워. 많은 시간을 절약 했어. –

+1

이렇게하면 문제가 해결됩니다. 고마워. – seleucia

관련 문제