This article discusses how to set up and compile C++ projects from the command line and popular IDEs.
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.
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.
Note: Visual Studio 2015 uses a different structure for its runtime libraries. We recommend creating a new project when using VS 2015 rather than trying to import one of the existing projects.
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.
- Choose the Debug configuration.
- Add the SDK include directory to your project:
Under Configuration Properties, select C/C++ > General.
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.)
- Add references to the Leap Motion libraries:
Under Configuration Properties, select Linker > General.
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
Select Linker > Input
Add Leap.lib to the Additional Dependencies field.
- Add a Post-Build Event to copy the Leap Motion libraries to the project’s target executable directory.
Under Configuration Properties, select Build Events > Post-Build Event.
Edit the Command Line field to copy the libraries, adding:xcopy /yr "$(LEAP_SDK)\lib\x86\Leap.dll" "$(TargetDir)"
- Choose the Release configuration.
- Repeat the setps above.
To set up a Leap Motion project in Xcode:
Open or create an Xcode project.
Add the Leap Motion SDK include files and API library:
Configure the project to bundle libLeap.dylib with the application:
- Go to the target Build Phases page.
- Add a build phase using the Menu command: Editor>Add Build Phase>Add Copy Files Build Phase.
- Open the new phase.
- Set destination to Executables.
- Add libLeap.dylib to the list of files.
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).