0

I want to integrate Box2d in my OS X application, so I've used the following Podfile to grab it:

pod 'box2d'

And the version of box2d is 2.3.0. In the xcworkspace I got from pod install, I've created a bridge header to interoperate with the C++ APIs (according to doc, developer cannot import C++ projects directly from Swift lang, you should create a ObjC bridge).

And when I hit build button, I got a compiler error:

<unknown>:0: error: /path/to/project/Pods/Headers/Box2D/Common/b2Settings.h:22: 'cassert' file not found

So I wonder how can I fix this?

Void Main
  • 2,241
  • 3
  • 27
  • 36
  • This might help: http://stackoverflow.com/questions/24042774/can-i-mix-swift-with-c-like-the-objective-c-mm-files – iforce2d Jul 01 '14 at 09:19

1 Answers1

1

Finally I figured it out by myself.

I've already created the bridging file as mentioned in apple's doc, but the content I was putting there was:

//
//  Use this file to import your target's public headers that you would like to expose to Swift.
//
#import <Box2d/Box2d.h>

This is the root for the compiler error. So, I have to create a new Objective-C class, rename the .m file to .mm, and put the line of import in the .mm file. NOTE: putting the import line in .h file does not solve the compiler error.

And that's it, now it compiles happily.

Void Main
  • 2,241
  • 3
  • 27
  • 36
  • Once you resolved this issue, how are you able to use Box2D in your Swift code? Can you provide a code sample? – andrewz Dec 24 '15 at 21:38