2015-02-24 53 views
3

最近我开始使用Windows上的Boost进行项目工作。它需要是跨平台的,所以我也在Mac上安装了它。不幸;每当我将它添加到Xcode项目时,它都会给我带来大量的链接错误和转换警告。Mac上的Boost链接器错误(OSX 10.10.02 | Xcode 6.1.1)

实例链接器错误之一:

Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from: ___cxx_global_var_init2 in main.o boost::asio::error::get_system_category() in main.o boost::system::error_code::error_code() 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)

转换的警告的一个实例:

In file included from /usr/local/Cellar/boost/1.57.0/include/boost/date_time/posix_time/posix_time_types.hpp:16: /usr/local/Cellar/boost/1.57.0/include/boost/date_time/posix_time/posix_time_duration.hpp:24:21: warning: implicit conversion loses integer precision: 'long' to 'hour_type' (aka 'int') [-Wshorten-64-to-32] time_duration(h,0,0)

我试了好几种安装方法和配置方法,但它仍然不会工作。

这是我的步骤:

  1. 编译升压或升压得到的编译版本。
  2. 创建一个XCode项目。
  3. 在主类中输入this示例代码。
  4. 将标题和库路径添加到Xcode项目文件。
  5. 构建。

编译选项我曾尝试:

  • 从源代码使用the official guide编译。
  • 使用几个脚本从源代码编译我在这里找到了Stackoverflow。
  • 安装brew包管理器并下载带有二进制文件的包。

配置选项我曾尝试:

  1. 设置为/usr/local/Cellar/boost/1.57.0/include或等同物和 的报头搜索路径设定库搜索路径到/ usr /local/Cellar/boost/1.57.0/lib或等价物。
  2. 只设置标题搜索路径而不设置库路径。
  3. 选项1但递归(导致更多错误)。

如果有人能指出我正确的方向,我将非常感激。我认为这是与Xcode相关的,因为所有的编译版本都给我提供了相同的错误。

回答

3

我找到了答案。将标题和库路径添加到项目搜索路径后,您需要转到“构建阶段”。您需要将所需的单个库添加到“链接库到二进制”子节中。您可以在lib文件夹中找到必要的文件(在boost文件夹中)。

您可以选择扩展名为.a的库文件或扩展名为.mt.dylib的库文件。如果您选择.a扩展名文件,则该库将被添加到您的程序的编译版本中。如果您选择.mt.dylib文件,那么这些库不会被添加到您的编译程序中。在这种情况下,您假设动态库文件已经存在于运行该程序的计算机上。