Setting Up a Project

This article discusses how to set up and compile Objective-C projects with Xcode. The Leap Motion Objective-C API is provided as a Objective-C++ wrapper that allows you to access the C++ API using pure Objective-C code. Every Objective-C project must include the following files:

  • and LeapObjectiveC.h – the API wrapper files.
  • Leap.h and LeapMath.h – The C++ header files used by the API wrapper.
  • libLeap.dylib – The Leap Motion dynamic library (compiled against libc++).

Mac OS X: Setting up a project in Xcode

To set up a Leap Motion project in Xcode:

  1. Open or create an Xcode project.

  2. Add the Leap Motion SDK include files and API library:

    1. Drag, LeapObjectiveC.h, Leap.h, and LeapMath.h into the project from the SDK include folder. Add these files to the appropriate targets so that they are compiled with your application source code.
    1. Drag libLeap.dylib into the project from the SDK lib folder. (Make sure to add it to the appropriate project targets.)
  3. Configure the project to bundle libLeap.dylib with the application:

  1. Go to the target Build Phases page.
  2. Add a build phase using the Menu command: Editor>Add Build Phase>Add Copy Files Build Phase.
  3. Open the new phase.
    1. Set destination to Executables.
    2. Add libLeap.dylib to the list of files.
  1. Add your source code...

Automatic Reference Counting (ARC)

The Leap Motion wrapper files, and LeapObjectiveC.h, require ARC. To use this wrapper in a non-ARC project, you have two options: You can switch the project as a whole to use ARC and then add the -fno-objc-arc flag to those components that cannot be easily converted. Alternately, you can compile the Leap Motion wrapper files with the -fobjc-arc flag.

Mac OS X: Loading the libLeap dynamic library from a different location

If you wish to load the libLeap dynamic library from a different location than your application executable, you can use the OS X install_name_tool to change the loader path. For example, to load the library from the Resources folder of a standard Mac application package instead of the MacOS folder, you could run the following command:

On Mac OS X:

install_name_tool -change @loader_path/libLeap.dylib @executable_path/../Resources/libLeap.dylib Sample

(where Sample is your application binary).