将Boost库链接到Xcode项目

linking Boost library to Xcode project

本文关键字:Xcode 项目 链接 Boost      更新时间:2023-10-16

我正在尝试创建一个使用Boost库的项目。我使用的是OS X 10.9.5(我应该更新一下),使用的是Xcode 6.2。我用自制的brew install boost安装了boost,它位于/usr/local/Cellar/boost/1.59.0中。我在Xcode中的头搜索路径中添加了/usr/local/Cellar/boost/1.59.0/include路径,它似乎能识别它,因为自动完成提示是有效的。

在boost文档中,它提到必须先构建一些boost库,然后才能使用它们。我想自制软件已经处理好了,因为我在/usr/local/Cellar/boost/1.59.0/lib 中有一堆.a.dylib文件

我还是C++和Xcode构建过程的新手,但似乎我仍然需要将编译的库链接到我的项目。我尝试将路径/usr/local/Cellar/boost/1.59.0/lib添加到项目的库搜索路径中,但我不确定这是否正确。

以下是我在尝试构建项目时遇到的错误。

Undefined symbols for architecture x86_64:
  "boost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
      boost::filesystem::create_directory(boost::filesystem::path const&) in main.o
  "boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
      boost::filesystem::exists(boost::filesystem::path const&) in main.o
  "boost::system::system_category()", referenced from:
      ___cxx_global_var_init2 in main.o
  "boost::system::generic_category()", referenced from:
      ___cxx_global_var_init in main.o
      ___cxx_global_var_init1 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)

我还需要配置其他东西才能使其工作吗?

添加路径是正确的,但您还需要指定所需的库。在命令行中,您可以使用-l,以便在Xcode中将它们添加到Other Linker Flags中。

您需要的库是boost_filesystemboost_system