c++xcodeboostfibers

How to enable boost library in xcode


I have a problem with adding boost library to my project in Xcode. It seems that some parts of boost work correctly but when I use some of them I get the following errors. Example- boost fiber library:

Undefined symbols for architecture arm64:
  "boost::fibers::future_category()", referenced from:
      std::make_error_code(boost::fibers::future_errc) in main.o
  "boost::fibers::condition_variable_any::notify_all()", referenced from:
      boost::fibers::condition_variable::notify_all() in main.o
  "boost::fibers::mutex::lock()", referenced from:
      std::__1::unique_lock<boost::fibers::mutex>::unique_lock(boost::fibers::mutex&) in main.o
  "boost::fibers::mutex::unlock()", referenced from:
      std::__1::unique_lock<boost::fibers::mutex>::unlock() in main.o
      std::__1::unique_lock<boost::fibers::mutex>::~unique_lock() in main.o
  "boost::fibers::wait_queue::empty() const", referenced from:
      boost::fibers::condition_variable_any::~condition_variable_any() in main.o
      boost::fibers::mutex::~mutex() in main.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Solution

  • You would need to manually add the library file in your Xcode. For instance, you were using boost/fiber, then you should at least add the corresponding library file libboost_fiber-mt.dylib in your Xcode project. The file should be located in hombrew/lib. And to add it, you can simply drag it to Targets->General->Frameworks and Libraries:

    enter image description here


    This should solve the majority of undefined symbol problems. Depends on your project, you might also want to add other libraries, such as libboost_context and libboost_filesystem to your project as well.