- 新建项目,创建新的win32控制程序
- 菜单->项目->项目属性
- 开始配置Debug
- 选择 (活动)Debug.
- 添加SDK至项目中:
在 配置属性 目录下, 选择 C/C++ > 常规.
在 属性 页面, 添加 SDK 的 include 根目录 到 附加包含目录 这一栏中:
$(LEAP_SDK)是LeapSDK的位置。如果设置环境变量没有成功,要么重配环境变量注销计算机让它生效,要么就使用绝对路径试一试。
- 添加Leap Motion库引用:
在 配置属性 下, 选择 链接器 > 常规.
在 属性 面板下, 添加 SDK中
lib\x86
根目录 (如果是64位机则添加lib\x64
) 到 附加库目录:本人是win8 64位系统 配置x86后运行成功。
选择 链接器 > 输入
添加
Leapd.lib
到 附加依赖项。.
- 添加预先生成事件来引用Leap Motion库到运行的项目文件中
在配置属性下, 选择生成事件->预生成事件。
编辑 命令行 来拷贝lib文件
- 设置 Release下的属性:
- 选择 Release.
- 如配置Debug一样配置include.
- 在链接器中添加库引用
Leap.lib
(注意不是Leapd.lib
).在 预生成事件中复制dll, 同样release下全是Leap.dll
.
- 添加代码就可以运行了
<span style="font-family:Comic Sans MS;font-size:12px;color:#333333;">#include <iostream> #include <string.h> #include "Leap.h" using namespace Leap; class SampleListener : public Listener { public: virtual void onConnect(const Controller&); virtual void onFrame(const Controller&); }; void SampleListener::onConnect(const Controller& controller) { std::cout << "Connected" << std::endl; } void SampleListener::onFrame(const Controller& controller) { std::cout << "Frame available" << std::endl; } int main(int argc, char** argv) { SampleListener listener; Controller controller; controller.addListener(listener); // Keep this process running until Enter is pressed std::cout << "Press Enter to quit..." << std::endl; std::cin.get(); // Remove the sample listener when done controller.removeListener(listener); return 0; }</span>