Ошибка при использовании boost::filesystem

Я пытаюсь прочитать все файлы .txt в заданную папку и пытаюсь использовать для этого библиотеки Boost:

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;
}

Но я получаю две ошибки компилятора:

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"

(Среди прочего, которые не имеют отношения к делу, такие как )

Что я делаю неправильно?


person Roman Rdgz    schedule 22.01.2015    source источник


Ответы (2)


Вам придется установить связь с -lboost_filesystem -lboost_system, чтобы устранить эти ошибки компоновщика.

Файловая система Boost зависит от другого скомпилированного компонента, доступного в этих библиотеках.

person P0W    schedule 22.01.2015

Это ошибки компоновщика, а не ошибки компилятора. Пожалуйста, дайте ссылку на библиотеку файловой системы boost, а также на системную библиотеку, файловая система b/c зависит от этого.

person FRob    schedule 22.01.2015