Lv.的博客

UE4中集成ProtoBuf

UE4Protobuf: UE4中编译最新Protobuf 3.11.2的脚本 (gitee.com)

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最新版(protobuf-cpp-x.x.x.zip)。

  2. 解压到source目录下

  3. 修改源代码

    • 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"
    • cmake/CMakeLists.txt

        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
    • includelibProtobuf.Build.cs拷贝到新建的目录下
    • 使用bin目录下生成protoc.exe生成*.pb.cc*.pb.h文件
    • 由于最新的Protobuf已经使用c++11重写,所以不需要再引入AllowWindowsPlatformTypes.h等文件了,基本不需要改动
posted @ 2021-06-22 18:16  Avatarx  阅读(1081)  评论(0编辑  收藏  举报