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)
2
Answers
The best way to install boost on a macOS from my experience is to install homebrew package manager. Then in a terminal enter brew install boost, this will install the boost library for you on your machine. To enable boost in Xcode open project then navigate to build setting from there select header search path and paste the location of the boost header files. (usually located in the usr/local/include) for the header and usually located in the usr/local/lib) for the library files. How to enable boost in xcode
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 filelibboost_fiber-mt.dylib
in your Xcode project. The file should be located inhombrew/lib
. And to add it, you can simply drag it toTargets->General->Frameworks and Libraries
: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
andlibboost_filesystem
to your project as well.