【问题标题】:linking Boost library to Xcode project将 Boost 库链接到 Xcode 项目
【发布时间】:2016-01-03 07:04:11
【问题描述】:

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

boost documentation 中提到必须先构建一些 Boost 库才能使用它们。我认为 homebrew 已经解决了这个问题,因为我在 /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)

我还需要配置什么其他东西才能让它工作吗?

【问题讨论】:

  • @Eelke 太棒了!谢谢我将这些添加到我的项目构建设置的Other Linker Flags 部分并且它有效!如果你把它作为一个答案,我会接受它

标签: c++ xcode boost


【解决方案1】:

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

您需要的库是boost_filesystemboost_system

【讨论】:

  • 你能给出确切的语法吗?我正在尝试使用 boost 并将 -l boost_bind 放在 Other Linker Flags 部分仍然在 Xcode 中给出“boost//bind.hpp 文件未找到”错误(#include <boost/bind/bind.hpp>#include <boost/bind.hpp> 都失败)
  • 您缺少 boost 的包含路径。无法提供详细信息,通过电话发布。
  • 我绝对不是。我用brew 安装了boost,它将它编译为/usr/local/Cellar/boost,我将/usr/local/Cellar/boost/1.65.1/include/ 添加到我的头文件路径中,并将/usr/local/Cellar/boost/1.65.1/lib/ 添加到库搜索路径中,但是当我查看实际的编译指令时(使用Xcode 的报告导航器)有 no 参考这些。所以我完全按照 Xcode 所说的那样添加了它们,然后它们就被完全忽略了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-06
  • 2011-09-01
相关资源
最近更新 更多