你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

安装 BuildProtobuf VS 2017

为 CNTK 创建编译的 Protobuf 3.1.0

如果要自行生成 Protobuf 3.1.0 CNTK,请遵循以下说明操作。 编译的 Protobuf 版本将位于 c:\local\protobuf-3.1.0-vs17

以下步骤假定 Protobuf 源已解压缩到目录 c:\local\src\protobuf-3.1.0。 下面的说明将在目录中 c:\local\protobuf-3.1.0-vs17创建 Protobuf 库和头文件。 如果此位置在案例中有所不同,请调整以下步骤以匹配目录结构。

可通过两种方法通过批处理文件手动生成 CNTK Protobuf 库。

通过批处理文件生成

在目录中 Tools\devInstall\Windows 找到批处理文件 buildProtoVS17.bat。 此批处理文件采用两个参数来生成 CNTK Protobuf 库。 第一个参数是上面解压缩的 Protobuf 源文件的目录,第二个参数是创建的 Protobuf 库的目标目录。 在本例中,请按照标准Windows命令提示符执行以下步骤:

c:
cd \repos\cntk\Tools\devInstall\Windows
buildProtoVS17 C:\local\src\protobuf-3.1.0 C:\local\protobuf-3.1.0-vs17

将环境变量 PROTOBUF_PATH 设置为 Protobuf 位置 (这是上述命令调用中的第二个参数,而不是源位置!

setx PROTOBUF_PATH c:\local\protobuf-3.1.0-vs17

CNTK Protobuf 库的手动生成步骤

注意

如果未VS2017INSTALLDIR由Visual Studio安装程序设置环境变量,请手动设置它。 具体安装目录取决于 2017 (版本,在本例中) 并提供 (Community、Enterprise等) Visual Studio,具体取决于以下模式: C:\Program Files (x86)\Microsoft Visual Studio\<version>\<offering>

对于 Visual Studio 2017 Enterprise 版本,请运行:

setx VS2017INSTALLDIR "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise"

对于 Visual Studio 2017 Community 版本,请运行:

setx VS2017INSTALLDIR "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community"
  1. 启动 64 位Visual Studio 2017 开发环境。 最简单的方法是使用标准 Windows 命令行界面中所需的参数在 Visual Studio 目录中执行批处理文件vcvarsall.bat
"%VS2017INSTALLDIR%\VC\Auxiliary\Build\vcvarsall.bat" amd64 --vcvars_ver=14.11

如果在系统上找不到此批处理文件,请重新访问 VS2017 的安装,并确保选择了“VC++版本 15.4 v14.11 工具集”选项。 2.创建生成目录:

cd C:\local\src\protobuf-3.1.0\cmake
mkdir build && cd build
  1. 创建调试版本:
mkdir debug && cd debug
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -DCMAKE_INSTALL_PREFIX="c:\local\protobuf-3.1.0-vs17" ..\..
nmake && nmake install
cd ..
  1. 创建发布版本:
mkdir release && cd release
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -DCMAKE_INSTALL_PREFIX="c:\local\protobuf-3.1.0-vs17" ..\..
nmake && nmake install
cd ..
  1. 将环境变量 PROTOBUF_PATH 设置为 Protobuf 位置 (注意:这是上述 cmake 命令中使用的安装位置,而不是源位置!) :
setx PROTOBUF_PATH c:\local\protobuf-3.1.0-vs17