Boost c ++库,链接器因Xcode而失败

时间:2018-03-25 15:27:09

标签: c++ xcode boost linker filesystems

我正在尝试在我的c ++ Xcode项目中使用boost,所以我编写了这个简单的代码来读取文件夹中文件的名称。

#include <boost/filesystem.hpp>
struct path_leaf_string
{
    std::string operator()(const boost::filesystem::directory_entry& entry) const {
        return entry.path().leaf().string();
    }
};

int main(){
    std::string name = ".";
    std::vector< std::string> v;
    boost::filesystem::path p(name);
    boost::filesystem::directory_iterator start(p);
    boost::filesystem::directory_iterator end;
    std::transform(start, end, std::back_inserter(v), path_leaf_string());
}

当然我在头搜索路径/usr/local/include中使用,在已安装boost的库搜索路径/usr/local/lib中使用,在其他链接器标志中我输入-lboost_system或我保持为空。 但是链接器仍然会返回此错误。

Undefined symbols for architecture x86_64:
    "boost::filesystem::detail::dir_itr_close(void*&, void*&)", referenced from:
        boost::filesystem::detail::dir_itr_imp::~dir_itr_imp() in main.o
    "boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, boost::system::error_code*)", referenced from:
        boost::filesystem::directory_iterator::directory_iterator(boost::filesystem::path const&) in main.o
    "boost::filesystem::detail::directory_iterator_increment(boost::filesystem::directory_iterator&, boost::system::error_code*)", referenced from:
        boost::filesystem::directory_iterator::increment() in main.o
    "boost::system::generic_category()", referenced from:
        boost::system::error_category::std_category::equivalent(int, std::__1::error_condition const&) const in main.o
        boost::system::error_category::std_category::equivalent(std::__1::error_code const&, int) const in main.o
    "boost::filesystem::path::filename() const", referenced from:
        boost::filesystem::path::leaf() const in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我使用Xcode 9.2和macOS HighSierra。 此外,我在Stackoverflow上尝试了所有推荐的解决方案但仍然无法正常工作 谢谢您的帮助。

0 个答案:

没有答案