# UE4Protobuf **Repository Path**: love_linger/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**: 19 - **Forks**: 7 - **Created**: 2019-12-17 - **Last Updated**: 2025-08-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # UEProtobuf 编译UE5使用的protobuf。 > 注:仅在 UE 5.6.0+ 上测试过 protobuf 32.0,如您的环境不一致,请自行改动。 ## 编译环境 1. Windows下编译Win64及Android库及UE使用的Linux库 * Visual Studio * Android NDK * CMake 并将cmake.exe所在目录加入系统变量`PATH`中 * 从UE官网下载 Cross-Compile Toolchains 2. Mac机编译Mac及IOS库 * XCode * CMake ## 使用说明 1. 下载[Google Protobuf](https://github.com/protocolbuffers/protobuf/releases)最新版(protobuf-cpp-x.x.x.zip)。 2. 解压并改名为`source`目录 3. 修改源代码 * 对于中国用户可能需要增加代理以下载依赖,修改方法,source\CMakeList.txt ``` set(ENV{http_proxy} "http://proxy_host:proxy_server_port") set(ENV{https_proxy} "http://proxy_host:proxy_server_port") ``` * source\src\google\protobuf\compiler\cpp\file.cc 函数:FileGenerator::GenerateSourceIncludes ```diff p->Print( "// Generated by the protocol buffer compiler. DO NOT EDIT!\n" "// NO CHECKED-IN PROTOBUF " "GENCODE\n" "// source: $filename$\n"); + +p->Print( + "\n" + "// Disable UE5 VS warnings\n" + "#ifdef _MSC_VER\n" + "# pragma warning(disable: 4065)\n" + "# pragma warning(disable: 4146)\n" + "# pragma warning(disable: 4244)\n" + "# pragma warning(disable: 4251)\n" + "# pragma warning(disable: 4267)\n" + "# pragma warning(disable: 4305)\n" + "# pragma warning(disable: 4307)\n" + "# pragma warning(disable: 4309)\n" + "# pragma warning(disable: 4334)\n" + "# pragma warning(disable: 4355)\n" + "# pragma warning(disable: 4506)\n" + "# pragma warning(disable: 4800)\n" + "# pragma warning(disable: 4996)\n" + "#endif\n"); + ``` 4. 编译 * 运行VS的`x64 Native Tools Command Prompt for VS XXX`,**cd**到工程目录执行`BuildWindows.bat` * 修改`BuildAndroid.bat`中**NDK**的路径 * 修改`BuildLinux.bat`中的**UE**所在路径 * 编译Mac及IOS: + STEP.1 Windows下共享工程目录 + STEP.2 Mac机下使用`mount_smbfs`指令挂载该目录 + STEP.3 执行`BuildIOS`及`BuildMac` 5. UE4集成 * 在项目`Source/ThirdParty`目录下建立文件夹`Protobuf` * 将`include`, `lib`, `Protobuf.Build.cs`拷贝到新建的目录下 * 使用`bin`目录下生成`protoc.exe`生成`*.pb.cc`及`*.pb.h`文件