在windows上编译voxel-sdk源码

windows上编译源文件

 

本节说明的过程建立在Windows 7 上的Voxel SDK。(括号里的是译者添加的内容)

 

一、前期准备

除了我在上一节讲到的需要安装的东西之外,你还需要安装下列软件到你的windows上:

  1. Cmake  [http://www.cmake.org/download/]
  2. Git  [http://git-scm.com/download/win]
  3. vs2013(上节已经提到过了)
  4. CypressCyAPI函数和库(用于usb通信的)你可能需要注册,并下载压缩文件,在里面找到CyAPI.hCyAPI.lib并拷贝到路径:voxel-sdk/Voxel/CyAPI 注意CyAPI的架构,x86x64 [http://www.cypress.com/?rID=34870]
  5. 警告:如果在此之前您有安装任何版本的Voxel-SDK 请先卸载,否则将会干扰构建。原因见二、3

 

二、可选的准备(按原文是这么翻译的,但是帮你自己个忙,都安上吧)

下面有两种可选的准备

  1. Doxygen 可用于生成源文档[http://ftp.stack.nl/pub/users/dimitri/doxygen-1.8.9.1-setup.exe]
  2. GraphViz Doxygen 生成类层次结构图(形象的标出了父类子类的图?我猜是这样吧。管他呢,安上) [http://www.graphviz.org/Download.php]
  3. SWIG 生成Python绑定。(上面的两项你可以选择不装,但是这一项必须安装,且必须在你安装Voxcel-SDK之前。这是译者血的教训)

如何安装SWIG(3.0及以上版本)

  1. 下载 swigwin.3.x.y.zip [http://prdownloads.sourceforge.net/swig/swigwin-3.0.5.zip]
  2. 提取压缩到路径: 'C:\Program Files',提取后,你应该能看到所有的SWIG相关安装文件在路径: 'C:\Program Files\swigwin-3.0.5'。(如果你和译者一样有强迫症,也可放到你自己喜欢的路径下,但是要记好这个路径,我指的是存一个记事本文件在你的桌面上)
  3. 现在,把 'C:\Program Files\swigwin-3.0.5'添加到环境变量PATH里。不会添加环境变量的话,自己百度去啊!
  4. 现在为了测试SWIG是否安装成功,打开cmd(为你自己好,用管理员模式),运行swig,如果出现类似“Must specify an input file. Use -help for available options” 必须指定一个输入文件。使用-帮助可用选项)这样的话,那么就成功了。
  5. 如果你没有安装SWIG,那么当你在配置voxcel库的时候,就会出现问题。你可以在这之后启动cmake-gui,并且不选 'GENERATE_PYTHON_BINDINGS'。这可以是你避免Python绑定,但是其余组件还是会正确编译。(但是译者没装这个SWIG就用cmake编译,结果失败了)

 

三、下载源码

你可以在GIT中利用下面的命令

git clone https://github.com/3dtof/voxelsdk.git(不带引号,你也可以用vpn在这个网上直接下载)

 

上面的命令会创建Voxcel-SDK文件夹源码和组件将会被检查

不出意外的话应该有下面5个子文件夹。

VoxelSDK库的核心

TI3DToF: TI的深度相机支持

VoxelPCL: PCL集成

App: voxelcli和其他应用程序

Test: 为个人测试程序

 

四、用源码编译

如果你已经把源码下载好了,那么你可以用如下的方式使用cmake进行配置和构建

cd voxel-sdk
mkdir build
cd build
set CMAKE_PREFIX_PATH=%CWD%;%CMAKE_PREFIX_PATH%
cmake-gui ..

 “(这里译者要说一下,如果你是个新手,不要直接复制以上代码,建议你最好先弄明白以上代码的意思,再进行下面的步骤。大致就是载入代码所在文件夹,建立build文件夹,进入build文件夹,设置两个环境变量,打开cmake-gui……磨刀不误砍柴工,配置平台的时候遇到的很多麻烦,都是因为对配置过程原理的不熟悉。)

当你看到这里时,译者希望你已经学会如何用cmake-gui生成vssln工程文件,否则不建议你继续看下去。当然即使你经验比较丰富,也需要从3仔细看起。如果你在此之前已经先安装好了任意版本的voxcel-sdk,那么情况3579讲道理不会出现。总之无论你用什么方式,打开cmake-gui后)

  1. 点击 'Configure' 选择 'Visual Studio 12 2013 Win64'64位编译, 'Visual Studio 12 2013 Win32'32位编译。
  2. 有关配置的消息在窗口中显示。
  3. 如果它找不到PCL PCL_DIR设为PCL的安装目录下版本号文件夹的一个cmake目录。
  4. 再点一下configure
  5. 如果找不到Boost,将BOOST_LIBRARYDIR设为lib64-msvc-12.0文件夹绝对路径BOOST_INCLUDEDIR设为Boost文件夹绝对路径。
  6. 4
  7. 如果找不到VTK,设置CMAKE_PREFIX_PATHvtk-6.1
  8. 6
  9. 如果找不到QT,设置Qt5Widgets_DIRQt5Widgets文件夹所在绝对路径,假设你安装了QT5。(没安你bb什么)
  10. 8,现在你应该成功了,(如果没有,检查一下swig有没有安装好。或者看看哪个文件报错。也可以尝试联系译者)
  11. 点击‘Generate'来生成解决方案和项目
  12. 现在您可以在build目录下打开.sln了,并进行构建和编译。也可以用命令“cmake --build . --target ALL_BUILD --config RelWithDebInfo “上述命令将用debug方式建立目标。如果你想编译release版,用 cmake --build . --target ALL_BUILD --config Release。或者你可以在vs里自行手动设置。(译者翻译不动了,你都生成sln了,后面就不用教了啊)

 

五、    运行

要想成功运行,你需要设置几个环境变量

PATH

C:\Program Files\PCL 1.7.2\bin
C:\Program Files\PCL 1.7.2\3rdParty\VTK\bin
C:\Qt\Qt5.4.0\5.4\msvc2013_win64\bin
<path_to_voxel_sdk_folder>\build\bin
<path_to_voxel_sdk_folder>\build\lib

 

VOXEL_SDK_PATH

<path_to_voxel_sdk_folder>\build

 

PYTHONPATH 

<path_to_voxel_sdk_folder>\build\lib\python2.7

 

以上的<path_to_voxel_sdk_folder>是你build所在的上级目录

 

(原文里有几句我比较在意由于一个错误,在Visual Studio 2013中,当你设置所需的环境变量时,你需要关闭vs,然后编辑对应的.user文件。将里面的换行符替换成&#xd;&#xa;.

 

 

六、创建安装包

如果你只是需要使用或者修改SDK那么创建安装包是不必要的。

在创建安装包之前,请确保 'NSIS'已经正确安装。[http://nsis.sourceforge.net/

现在,在生成目录中运行以下命令—

cmake --build . --target PACKAGE --config Release

你用vs中的 'PACKAGE'也可以达到同样的效果。

 

注意:对于这项工作,vs必须用管理员模式运行。Voxel SDK-<version>-Win<arch>.exe在你编译的目录下的这个文件就是安装包了。


下面附上原文

Build from source on Windows

Prasad H L Bhat edited this page  on 27 Apr ·  13 revisions

This section explains the process to build Voxel SDK source on Windows 7.

Pre-requisites

Apart from the pre-requisites mentioned in Installation on Windows, you need to install the following -

  1. CMake - Download and install from [http://www.cmake.org/download/]
  2. Git - Download and install from [http://git-scm.com/download/win]
  3. Visual Studio 2013 Express Edition or better - Download and install from [http://go.microsoft.com/?linkid=9832256]. You'll to sign-in with a Microsoft account to download this. Make sure you also install Update 4 or later.
  4. CyAPI header and library from Cypress. Download Cypress SuiteUSB 3.4 from here file [http://www.cypress.com/?rID=34870]. You might need to register to download this ZIP file. Inside it, find CyAPI.h and CyAPI.lib and copy it to voxel-sdk/Voxel/CyAPI folder, to be download later in the next section. CyAPI.lib needs to be of appropriate architecture (64-bit/32-bit)

WARNING: If you have any version of Voxel-SDK installed, kindly uninstall using the 'Programs and Features' option from your Windows Control Panel. Otherwise, it will interfere with the build.

Optional Pre-requisites

There are two optional pre-requisites,

  1. Doxygen -- for generating source documentation. Download and install from [http://ftp.stack.nl/pub/users/dimitri/doxygen-1.8.9.1-setup.exe]
  2. GraphViz -- for generating class heirarchy images for Doxygen [http://www.graphviz.org/Download.php]
  3. SWIG -- for generating Python bindings.

To install SWIG (>= 3.0),

  1. Download swigwin.3.x.y.zip from [http://prdownloads.sourceforge.net/swig/swigwin-3.0.5.zip]
  2. Extract the ZIP to 'C:\Program Files'. After extraction, you should see all SWIG related files installed in 'C:\Program Files\swigwin-3.0.5'
  3. Now, add 'C:\Program Files\swigwin-3.0.5' to 'Path' environment variable. To know how to set an environment variable, see [http://www.computerhope.com/issues/ch000549.htm].
  4. To test whether SWIG is properly installed, open a command prompt (CMD) and run 'swig'. This should report an error similar to
    Must specify an input file. Use -help for available options

If you do not have SWIG installed, then while configuring libvoxel, you will get an error regarding SWIG not found. You can then launch the 'cmake-gui' and unselect 'GENERATE_PYTHON_BINDINGS'. This would avoid generation of Python bindings, but rest of the components will be built as is.

Download source

To download the voxel-SDK run the below command in git bash

git clone https://github.com/3dtof/voxelsdk.git

This would create a folder 'voxel-sdk' where the source code of Voxel-SDK and all its components will be checked out.

The repository has 5 subfolders:

  1. Voxel - the Core Voxel-SDK library
  2. TI3DToF - For TI's depth camera support
  3. VoxelPCL - For Voxel-PCL integration
  4. App - For VoxelCLI and other apps
  5. Test - For individual test programs

Build from source

Once the source code is download, you can use CMake to configure and build as follows.

cd voxel-sdk
mkdir build
cd build
set CMAKE_PREFIX_PATH=%CWD%;%CMAKE_PREFIX_PATH%
cmake-gui ..

This will open a GUI with multiple options.

  1. Click on 'Configure' and select 'Visual Studio 12 2013 Win64' for 64-bit build or 'Visual Studio 12 2013 Win32' for 32-bit build.
  2. The messages related to configuration are shown in the window.
  3. If it could not find PCL, edit PCL_DIR in the top list of parameters, and set it to 'cmake' directory present in the location where PCL is installed. E.g.: If you have installed PCL to C:/Program Files/PCL-1.7.2 then, set PCL_DIR to C:/Program Files/PCL-1.7.2/cmake
  4. Run configure again.
  5. If it could not find Boost, add entry 'BOOST_LIBRARYDIR' of type 'PATH' and set it toC:/Program Files/PCL-1.7.2/3rdParty/Boost/lib64-msvc-12.0 Also, set 'BOOST_INCLUDEDIR' of type 'PATH' to C:/Program Files/PCL-1.7.2/3rdParty/Boost
  6. Run configure again
  7. If it could not find VTK, add to 'CMAKE_PREFIX_PATH', folder path C:/Program Files/PCL-1.7.2/3rdParty/VTK/lib/cmake/vtk-6.1
  8. Run configure again
  9. If it could not find Qt, set 'Qt5Widgets_DIR' toC:/Qt/Qt5.4.0/5.4/msvc2013_64/lib/cmake/Qt5Widgets assuming you have installed Qt5 inC:/Qt/Qt5.4.0
  10. Run configure again. Now it should succeed.
  11. Now click on 'Generate' to generate solution and projects for Visual Studio 2013
  12. You can now either open '.sln' present in build directory and compile 'ALL_BUILD' or run in command line cmake --build . --target ALL_BUILD --config RelWithDebInfo The above command with build the target with debug information. If you want Release build without debug information, do the following in command line. cmake --build . --target ALL_BUILD --config Release In visual studio, you can right-click on the solution and go to Properties, and set the configuration to 'Release'. Then, build 'ALL_BUILD' project to build the whole solution in Release mode.

Running SDK programs

To run from compiled code as is, then you need to set a few environment variables in user/system (see [http://www.computerhope.com/issues/ch000549.htm]) or locally in the prompt or program where you intend to run an SDK program. To set environment variable in local command prompt, see [http://ss64.com/nt/set.html]. To set environment variable in Visual Studio to run an SDK program, see [http://stackoverflow.com/questions/14520786/visual-c-define-multiple-environment-variables-for-debug]. Due to a bug, in Visual Studio 2013, after you have set the required environment variables, you need to close the Visual studio and edit the ".user" file corresponding to the target, and replace all newlines within with &#xd;&#xa;.

The following environment variables need to be set:

  • Set PATH to include the following at the beginning -
C:\Program Files\PCL 1.7.2\bin
C:\Program Files\PCL 1.7.2\3rdParty\VTK\bin
C:\Qt\Qt5.4.0\5.4\msvc2013_win64\bin
<path_to_voxel_sdk_folder>\build\bin
<path_to_voxel_sdk_folder>\build\lib
  • Set VOXEL_SDK_PATH to <path_to_voxel_sdk_folder>\build

  • Set PYTHONPATH to include <path_to_voxel_sdk_folder>\build\lib\python2.7 at the beginning. This is necessary only if you plan to use the Python API of the SDK.

In the above, <path_to_voxel_sdk_folder> needs to be replaced with absolute path of "voxel-sdk" folder cloned from GIT, in the previous step.

Create Installable Packages

Creation of an installable is not necessary if you want to use or modify the SDK.

To create installable package, please ensure that 'NSIS' [http://nsis.sourceforge.net/] is installed in your system. Now, run the following command in the build directory -

cmake --build . --target PACKAGE --config Release

In visual studio, build 'PACKAGE' project for similar effect.

NOTE: For this work, you need run the command prompt/visual studio with administrator privileges.

This would create an installable package Voxel SDK-<version>-Win<arch>.exe in the build directory.


猜你喜欢

转载自blog.csdn.net/gua_MASS/article/details/51819796