1.下载源码protobuf-3.10.0
2.解压源码到工作目录
3.找到解压目录下的cmake/README.md
4.依次按照其步骤编译
README.md步骤
1.打开Native Tools Command Prompt(VS2013是VS2013 x64 本机工具命令提示,VS2017是VS 2017的 x64_x86 交叉工具命令提示符),VS2013和VS2017该工具的路径也不一样,注意区分
2.在Cmd命令下进入解压目录同级目录,比如第一步解压在C:\Path\to目录下,执行C:\Path\to>mkdir install,创建install目录,在编译过程中,这个目录并没什么用,暂时创建出来就可
3.假如命1中的工具不在环境变量,将其加入环境变量。配置git,因为后面如果没有提前下载源码的zip包,是在cmd下使用git下载
C:\Path\to> git clone -b [release_tag] https://github.com/protocolbuffers/protobuf.git
4.进入解压目录, C:\Path\to>cd protobuf
5.进入cmake目录,C:\Path\to\protobuf>cd cmake。C:\Path\to\protobuf\cmake>
6.创建build目录,并进入build目录。 C:\Path\to\protobuf\cmake>mkdir build & cd build
C:\Path\to\protobuf\cmake\build>
7.创建release目录。
C:\Path\to\protobuf\cmake\build>mkdir release & cd release
C:\Path\to\protobuf\cmake\build\release>cmake -G "NMake Makefiles" ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=../../../../install ^
../..
8.创建debug目录
C:\Path\to\protobuf\cmake\build>mkdir debug & cd debug
C:\Path\to\protobuf\cmake\build\debug>cmake -G "NMake Makefiles" ^
-DCMAKE_BUILD_TYPE=Debug ^
-DCMAKE_INSTALL_PREFIX=../../../../install ^
../..
9.创建解决方案目录
C:\Path\to\protobuf\cmake\build>mkdir solution & cd solution
C:\Path\to\protobuf\cmake\build\solution>cmake -G "Visual Studio 14 2015 Win64" ^
-DCMAKE_INSTALL_PREFIX=../../../../install ^
../..
10.编译。编译的话分两种,一种是通过nmake编译,一种是通过VS的sln编译,我们选择第9步生成的。
11.打开sln,protobuf.sln,如果已经下载了protoc.exe,在只需要编译libprotobuf工程,否则还得编译libprotoc工程。
12.遇到v140工具的问题,打开VS的安装器(VS installer,VS菜单栏->帮助->检查更新->打开Visual Studio安装程序,选在安装器界面的,更多->更改->单个组件,搜索框搜索v140,安装适用于桌面的VC++2015.3 v14.00(v140)工具集),继续生成libprotobuf,release。
13.生成incluede目录,执行extract_includes.bat
14.如果需要Zlib,则进行Zlib库安装,目前我仅进行到13,没有安装ZLib
15.将生成的生成的include和lib拷贝到UE4中,添加头文件包含目录和库包含目录,以及库的引用。
16.修改.Build.cs,添加lib的路径
public class ExcelPBC : ModuleRules
{
private string ModulePath
{
get
{
return ModuleDirectory;
}
}
private string ThirdPartyPath
{
get
{
return Path.GetFullPath(Path.Combine(ModulePath, "../ExcelPBC/ThirdParty/ProtoBuffer"));
}
}
public ExcelPBC(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay" });
PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "include"));
PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath,"lib", "libprotobuf.lib"));
}
}
17.添加由protoc生成的.proto对应的.cc和.h文件,编译UE4,会报错,见注意事项3。
注意事项:
1.v140的安装
2.属性配置修改:如果UE使用protocbuff,则需要修改当前项目属性->配置属性->C/C++->代码生成,选择运行库,设置为多线程DLL(/MD),不然UE4会找不到lib
3.修改.cc,消除UE4产生的警告和报错
参考链接:http://www.v5xy.com/?p=925