2015-01-22 7 views
0

내가 특정 폴더에있는 모든 .txt 인 파일을 읽을려고, 나는 그것에 대해 부스트 라이브러리를 사용하는 것을 시도하고있다 :오류 사용하여 부스트 : : 파일 시스템

int FileLoad::ReadTxtFiles(const std::string folder){ 
    int loadStatus = LOAD_OK; 

    // Check if given folder exists 
    if(boost::filesystem::is_directory(folder)){ 
     // Iterate existing text files 
     boost::filesystem::directory_iterator end_iter; 
     for(boost::filesystem::directory_iterator dir_itr(folder); 
      dir_itr!=end_iter; dir_itr++){ 

      boost::filesystem::path filePath; 
      try{ 
       // Check if it is a file 
       if(boost::filesystem::is_regular_file(dir_itr->status())){ 
        filePath = dir_itr->path(); 
        // Check that it is .txt extension 
        std::string fileExtension = 
         dir_itr->path().extension().string(); // Case insensitive comparison 
        if(boost::iequals(fileExtension, ".txt")){ 
         // Filename is the code used as id when the file text is loaded to a database 
         std::string fileName = dir_itr->path().stem().string(); 
         std::istringstream is(fileName); 
         unsigned int entryId; 
         is >> entryId; 
         // Check if an entry with that code id currently exists 
         // at the database 
         if(!DATABASE::CheckIfEntryExists(entryId)){ 
          // Process text file 
          loadStatus = ProcessFile(filePath.string()); 
         } 
        } 
       } 
      } 
      catch(const std::exception& ex){ 
       std::cerr << " [FILE] Error trying to open file " << 
        filePath.string() << std::endl; 
      } 
     } 
    } 

    return loadStatus; 
} 

을하지만 두 개의 컴파일러 오류를 reeiving하고 있습니다 :

undefined reference to `boost::filesystem3::path::extension() const' 
undefined reference to `boost::filesystem3::path::stem() const' 

내가 가지고있는 클래스 헤더 파일에 다음 수입 : 관련이없는 다른 사람들 중에서

#include "boost/algorithm/string.hpp" 
#include "boost/filesystem/operations.hpp" 
#include "boost/filesystem/path.hpp" 

(S uch)

내가 뭘 잘못하고 있니?

답변

2

당신은 오류를 컴파일러, 해당 라이브러리

2

그 링커 오류가에

부스트 파일 시스템을 사용할 수있는 다른 컴파일 된 구성 요소에 따라 그 링커 오류를하지 해결하기 위해, -lboost_filesystem -lboost_system와 연결해야합니다. 부스트 파일 시스템 라이브러리와 시스템 라이브러리에 대해서도 링크하십시오. b/c 파일 시스템은 그것에 의존합니다.

관련 문제