在Mac上使用Boost进行链接器错误(OSX 10.10.02 | Xcode 6.1.1) [英] Linker errors with Boost on Mac (OSX 10.10.02 | Xcode 6.1.1)

查看:84
本文介绍了在Mac上使用Boost进行链接器错误(OSX 10.10.02 | Xcode 6.1.1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我开始在Windows上使用Boost处理一个项目.它需要跨平台,因此我也将其安装在Mac上.很遗憾;每当我将其添加到Xcode项目中时,都会给我带来大量的链接器错误和转换警告.

Recently I started working with Boost on Windows for a project. It needs to be cross-platform so I also installed it on Mac. Unfortunately; whenever I add it to the Xcode project it gives me a big slew of linker-errors and conversion-warnings.

链接错误之一的示例:

x86_64体系结构的未定义符号:
"boost :: system :: system_category()",引用自: ___cxx_global_var_init2在main.o中 main.o中的boost :: asio :: error :: get_system_category() 在main.o中的boost :: system :: error_code :: error_code()"boost :: system :: generic_category()",引用自: ___cxx_global_var_init在main.o中 ___cxx_global_var_init1在main.o ld中:找不到架构x86_64的符号clang:错误:链接器命令失败,并带有退出代码 1(使用-v查看调用)

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)

其中一个转换警告示例:

Example of one of the conversion-warnings:

包含在以下文件中 /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:警告:隐式转换失去整数精度:"long"到 'hour_type'(aka'int')[-Wshorten-64-to-32] time_duration(h,0,0)

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)

我尝试了几种安装方法和配置方法,但仍然无法正常工作.

I tried several installation methods and configuration methods but it still won't work.

这些是我的步骤:

  1. 编译Boost或获取Boost的编译版本.
  2. 创建一个XCode项目.
  3. 输入主类中的示例代码.
  4. 将标头和库路径添加到Xcode项目文件中.
  5. 构建.
  1. Compile Boost or get a compiled version of Boost.
  2. Create an XCode project.
  3. Enter this sample code in the main class.
  4. Add the header and library paths to the Xcode project file.
  5. Build.

我尝试过的编译选项:

  • 使用官方指南从源进行编译.
  • 使用我在Stackoverflow上找到的一些脚本从源代码进行编译.
  • 安装冲泡软件包管理器并下载包含二进制文件的软件包.

我尝试过的配置选项:

  1. 将标头搜索路径设置为/usr/local/Cellar/boost/1.57.0/include或等效文件,以及 将库搜索路径设置为/usr/local/Cellar/boost/1.57.0/lib或等效文件.
  2. 仅设置标题搜索路径,而不设置库路径.
  3. 选项1但递归(导致更多错误).
  1. Setting the header search path to /usr/local/Cellar/boost/1.57.0/include or equivalents and setting the library search path to /usr/local/Cellar/boost/1.57.0/lib or the equivalents.
  2. Setting just the header search path but not the library path.
  3. Option 1 but recursive (causes more errors).

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

I would appreciate it a lot if someone could point me in the right direction. I think it's something Xcode related since all of the compiled versions give me the same errors.

推荐答案

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

I found the answer. After the header- and library paths are added to the projects search paths you need to go to "Build Phases". There you need to add the individual libraries you need to the "link libraries to binary" subsection. You can find the necessary files in the lib folder (in the boost folder).

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

You can choose for either the library files with .a extension or with the .mt.dylib extension. If you choose the .a extension files the library will be added to the compiled version of your program. If you choose the .mt.dylib files then the libraries will not be added to your compiled program. In this case you are assuming the dynamic library files are already present on the computer running the program.

这篇关于在Mac上使用Boost进行链接器错误(OSX 10.10.02 | Xcode 6.1.1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆