gpt4 book ai didi

c++ - Mac 上 Boost 的链接器错误 (OSX 10.10.02 | Xcode 6.1.1)

转载 作者:太空狗 更新时间:2023-10-29 21:18:58 26 4
gpt4 key购买 nike

最近我开始在 Windows 上使用 Boost 进行一个项目。它需要跨平台,所以我也在 Mac 上安装了它。很遗憾;每当我将它添加到 Xcode 项目时,它都会给我一大堆链接器错误和转换警告。

链接器错误之一的示例:

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. 编译 Boost 或获取 Boost 的编译版本。
  2. 创建一个 XCode 项目。
  3. 输入this主类中的示例代码。
  4. 将 header 和库路径添加到 Xcode 项目文件。
  5. 构建。

我试过的编译选项:

  • 使用 the official guide 从源代码编译.
  • 使用我在 Stackoverflow 上找到的一些脚本从源代码进行编译。
  • 安装 brew 包管理器并下载包含二进制文件的包。

我尝试过的配置选项:

  1. 将 header 搜索路径设置为/usr/local/Cellar/boost/1.57.0/include 或等效路径,并且将库搜索路径设置为/usr/local/Cellar/boost/1.57.0/lib 或等效路径。
  2. 仅设置 header 搜索路径而不设置库路径。
  3. 选项 1 但递归(导致更多错误)。

如果有人能指出正确的方向,我将不胜感激。我认为这与 Xcode 相关,因为所有编译版本都会给我同样的错误。

最佳答案

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

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

关于c++ - Mac 上 Boost 的链接器错误 (OSX 10.10.02 | Xcode 6.1.1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28696243/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com