一、首先下载并编译Protobuf,在编译时,需要修改相应源代码:
1.src/google/protobuf/compiler/cpp/cpp_file.cc
// 方法:FileGenerator::GenerateSourceIncludes
format(
"// Generated by the protocol buffer compiler. DO NOT EDIT!\n"
"// source: $filename$\n"
+ "\n"
+ "// Disable UE4 VS warnings\n"
+ "#ifdef _MSC_VER\n"
+ "#\tpragma warning(disable: 4946)\n"
+ "#\tpragma warning(disable: 4125)\n"
+ "#\tpragma warning(disable: 4647)\n"
+ "#\tpragma warning(disable: 4668)\n"
+ "#\tpragma warning(disable: 4800)\n"
+ "#endif\n"
+ "\n"
"#include $1$\n"
2.cmake/CMakeLists.txt
add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD)
+ add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI=1)
二、在项目/插件的Source文件夹中创建ThirdParty/Protobuf文件夹,将include
,lib,
Protobuf.Build.cs
拷贝到新建的目录,在项目/插件的Build.cs文件中添加Protobuf模块:
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"Protobuf",
// ... add other public dependencies that you statically link with here ...
}
);
注:VS中出现标红错误不影响代码编译,编译过就行