# Setting Up a Project¶

This article discusses how to set up and compile C++ projects from the command line and popular IDEs.

## Compilers and libraries¶

On Windows, you can use the Visual C++ compiler included with Visual Studio 2008, 2010, or 2012. On OS X and Linux, you can use the gcc or clang compiler.

On Windows, the Leap Motion C++ API is provided in the dynamically linked library, Leap.dll. Separate libraries are provided for 32-bit, x86 architectures and 64-bit, x64 architectures.

On Mac OS X, the Leap Motion C++ API is provided in the dynamic library, libLeap.dylib. The OS X library supports both 32-bit and 64-bit architectures.

On Linux, the Leap Motion C++ API is provided in the shared library, libLeap.so. Separate libraries are provided for 32-bit, x86 architectures and 64bit, x64 architectures. The libraries use the libstdc++ standard library.

The Leap Motion dynamic libraries are designed to be loaded from the same directory as your application executable. You are expected to distribute the appropriate Leap Motion library with your application. The Leap Motion libraries are located in the lib folder of the Leap SDK package.

## Compiling and linking from the command line¶

The following examples illustrate how to compile and run Leap-enabled C++ applications from a terminal window or command line. The examples compile and run the Sample.cpp program included in the SDK. The current, working directory must be the SDK Samples folder for the commands to work as written.

### On Windows¶

It is simplest to run the Visual C++ compiler from the Visual Studio command prompt. The Visual Studio command prompt automatically sets up the environment variables to make it easy to run the compiler and linker. The Leap Motion SDK provides different libraries for 32-bit and 64-bit architectures: the 32-bit libraries are in the SDK lib\x86 folder; the 64-bit libraries are in lib\x64.

For 32-bit:

mkdir Release
cl /EHsc /I ..\include Sample.cpp /link ..\lib\x86\Leap.lib /OUT:Release\Sample.exe
xcopy ..\lib\x86\Leap.dll Release
Release\Sample


For 64-bit:

mkdir Release
cl /EHsc /I ..\include Sample.cpp /link ..\lib\x64\Leap.lib /OUT:Release\Sample.exe
xcopy ..\lib\x64\Leap.dll Release
Release\Sample


### On Mac OS X and Linux¶

A Makefile is supplied in the SDK samples folder. This makefile is setup to compile the Sample.cpp program, but you can adapt it to build your own programs.

## Windows: Setting up a C++ project in Visual Studio¶

The Leap Motion SDK package includes sample projects for Visual Studio 2008, 20010, and 2012. You can use these projects as a starting point for your Leap Motion projects. This section illustrates how to create a project from scratch. Most of the steps also apply to adding Leap Motion support to an existing project. The example uses Visual Studio 2012.

To add Leap Motion support to a new or existing project:

Important: If you are creating a 64-bit application, use the libraries in the lib\x64 directory of the SDK, not the 32-bit libraries in the lib\x86 directory.

1. Open or create a new project of the desired type.
2. Make a LEAP_SDK system environment variable to point to your Leap Motion SDK folder. This step is optional, but does simplify creating references to the SDK files in your projects. (As a reminder, you can create and change system environment variables from the Windows System Properties dialog.)
3. Open the Project Property Pages using the Project > Properties menu command.
4. Set up a Debug configuration:
1. Choose the Debug configuration.
1. Under Configuration Properties, select C/C++ > General.

2. In the properties pane, add the SDK include directory to the Additional Include Directories field by adding:

$(LEAP_SDK)\include  (where LEAP_SDK is the name of the environment variable you created earlier. You can substitute the appropriate file path if you do not want to use an environment variable.) 1. Add references to the Leap Motion libraries: 1. Under Configuration Properties, select Linker > General. 2. In the properties pane, add the SDK lib\x86 directory (or lib\x64 for 64-bit configurations) to the Additional Library Directories field by adding: $(LEAP_SDK)\lib\x86


1. Add a Post-Build Event to copy the Leap Motion libraries to the project’s target executable directory.
1. Under Configuration Properties, select Build Events > Post-Build Event.

2. Edit the Command Line field to copy the libraries, adding:

xcopy /yr "$(LEAP_SDK)\lib\x86\Leap.dll" "$(TargetDir)"

1. Set up a Release configuration:
1. Choose the Release configuration.
2. Repeat the setps above.

## 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 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.
3. Open the new phase.
1. Set destination to Executables.
2. Add libLeap.dylib to the list of files.
install_name_tool -change @loader_path/libLeap.dylib @executable_path/../Resources/libLeap.dylib Sample