# UE4Protobuf **Repository Path**: linkaka/UE4Protobuf ## Basic Information - **Project Name**: UE4Protobuf - **Description**: UE4中编译最新Protobuf 3.11.2的脚本 - **Primary Language**: C++ - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 7 - **Created**: 2022-12-28 - **Last Updated**: 2022-12-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # UE4Protobuf UE4中编译最新Protobuf 3.11.2的脚本 ## 编译环境 1. Windows下编译Win64及Android库 * Visual Studio * Android NDK * CMake 并将cmake.exe所在目录加入系统变量`PATH`中 2. Mac机编译IOS库 * XCode * CMake ## 使用说明 1. 下载[Google Protobuf](https://github.com/protocolbuffers/protobuf/releases)最新版(protobuf-cpp-x.x.x.zip)。 2. 解压到`source`目录下 3. 修改源代码 * src/google/protobuf/compiler/cpp/cpp_file.cc ```diff // 方法: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" ``` * cmake/CMakeLists.txt ```diff add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD) + add_definitions(-DGOOGLE_PROTOBUF_NO_RTTI=1) ``` 4. 编译 * 修改`BuildWindows.bat`中**VC**的路径为自己安装的路径 * 修改`BuildAndroid.bat`中**NDK**的路径 * Windows下运行`BuildWindows.bat` * Windows下运行`BuildAndroid.bat` * Mac下运行`BuildIOS.sh` 5. UE4集成 * 在项目`Source/ThirdParty`目录下建立文件夹`Protobuf` * 将`include`, `lib`, `Protobuf.Build.cs`拷贝到新建的目录下 * 使用`bin`目录下生成`protoc.exe`生成`*.pb.cc`及`*.pb.h`文件 * 由于最新的Protobuf已经使用c++11重写,所以不需要再引入`AllowWindowsPlatformTypes.h`等文件了,基本不需要改动