3
votes

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.

Example of one of the linker-errors:

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:

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.

These are my steps:

  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.

Compile options I have tried:

  • Compiling from source using the official guide.
  • Compiling from source using a few scripts I found here on Stackoverflow.
  • Installing the brew package manager and downloading a package with binaries.

Configuration options I have tried:

  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).

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.

1

1 Answers

3
votes

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).

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.