Liran Haim
Liran Haim

Reputation: 81

c++ Boost Mix with objective-c

I am trying to build c++ project that using boosts. I create a objective-c++ class that using OSX-SDK-9 and I plan to us the class from normal c++ class that have boosts includes. The object-c++ using SDK frameworks:

AppKit.framework
CoreGraphics.framework

and it have the includes

#include <ApplicationServices/ApplicationServices.h>
#include <Carbon/Carbon.h>
#include <AppKit/AppKit.h>
#include <AppKit/NSEvent.h>

When I add the include of the object-c++ to the boost class I see compiled errors Error When I remove the boost include the build succeeds

The boots is compiled in static library

Build the code with the follow parameters

xcode 6.3.2(6D2105)
compiler Apple LLVM6.1
GUN++11 [-std=gun++11]
libc++(LLVM c++ standard library with c++11 support)

What I doing wrong? How i can use c++ boost and OSK SDK with the same program

Upvotes: 1

Views: 196

Answers (2)

Vadim Peretokin
Vadim Peretokin

Reputation: 2816

Including AppKit headers prior to the Boost ones solves this particular problem.

Another problem will come up - expected unqualified-id, it can be solved by -

#include <AppKit/AppKit.h>
#undef nil
#include "boost headers here"
#define nil nullptr

Upvotes: 0

Michael Domino
Michael Domino

Reputation: 419

Looks like this is a name collision between Boost's Collection type and the Carbon Collection Manager.

"Collection" is defined in this header:

#include <CarbonCore/Collections.h>

And the symbol "Collection" is used in several places in boost.

The build log should show the exact boost header that is causing the problem. You can include a smaller subset of the boost headers to avoid the "Collection" symbol, or maybe write the functions that use boost in a separate source code file to avoid the clash.

Upvotes: 1

Related Questions