I'm trying to get Boost C++ 1.78.0 working on an iOS project. There are several options out there, building from source, a static library, creating an xcframework, etc. This one focuses on build issues using the homebrew installed boost.
In full disclaimer this is my first time incorporating Objective-C & C++ in an iOS Xcode project, so it's entirely likely I'm doing something simple and obvious incorrectly.
The process is:
- Install boost on the local machine
homebrew install boost
- Add a header search to the correct homebrew include dir:
HEADER_SEARCH_PATHS = /opt/homebrew/include;
Depending on your installation this may be /usr/local/include
. Just make sure @boost is found when you ls
that directory.
- Add a library search path:
LIBRARY_SEARCH_PATHS = /opt/homebrew/lib;
- Include a boost header in an Objective-C file in the Xcode project such as:
#import <boost/property_tree/ptree.hpp>
After doing this, the build errors show up:
In file included from ~/Desktop/Boost Test/Boost Test/Boost.m:10:
In file included from /opt/homebrew/include/boost/property_tree/ptree.hpp:15:
In file included from /opt/homebrew/include/boost/property_tree/ptree_fwd.hpp:15:
/opt/homebrew/include/boost/optional/optional_fwd.hpp:21:1: error: unknown type name 'namespace'
namespace boost {
^
/opt/homebrew/include/boost/optional/optional_fwd.hpp:21:16: error: expected ';' after top level declarator
namespace boost {
^
;
In file included from ~/Desktop/Boost Test/Boost Test/Boost.m:10:
In file included from /opt/homebrew/include/boost/property_tree/ptree.hpp:15:
In file included from /opt/homebrew/include/boost/property_tree/ptree_fwd.hpp:16:
In file included from /opt/homebrew/include/boost/throw_exception.hpp:23:
/opt/homebrew/include/boost/exception/exception.hpp:10:10: fatal error: 'exception' file not found
#include <exception>
^~~~~~~~~~~
3 errors generated.
The list of errors changes/grows depending on which files you import and what they require. But it's a mixture of the same kind of stuff.
Lastly. Here's a super simple demo project that exhibits the issue: https://github.com/Archdoog/boost-xcode-build-failure. This should allow easy reference of the .pbxproj
, etc.