0

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:

  1. Install boost on the local machine
homebrew install boost
  1. 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.

  1. Add a library search path:
LIBRARY_SEARCH_PATHS = /opt/homebrew/lib;
  1. 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.

Archdoog
  • 822
  • 9
  • 8
  • Are you sure you can include C++ header files in Objective-C source code? (I don't no much about Objective-C & Objective-C++ so I might be wrong here) – Debaug Apr 15 '22 at 14:50
  • From what I've read in things like this and elsewhere: https://stackoverflow.com/questions/32541268/can-i-have-swift-objective-c-c-and-c-files-in-the-same-xcode-project/32546879#32546879. The process of using C++ in Swift basically requires building an Objective-C wrapper. You can see in the example where both a `.h` and `.hpp` file are imported in the same file. I've messed around with various configurations using several of guides and seem to have the same build errors. Leads me to believe that something else is configured wrong. But I also don't have much experience here at this point. – Archdoog Apr 15 '22 at 17:36

0 Answers0