UE4编译grpc,编译打包
一.源码下载与编译
- 下载UE4.27.2源码
需要先注册UE的账号:
https://www.unrealengine.com/zh-CN/
需要有github.com账号
https://github.com/
登录ue4官网,点击个人,然后关联。
(注意有的人是很久之前注册过的,也关联过GitHub账号的,但是没有加入EpicGame的team,导致下载不了源码引擎。可以点解除关联,然后再重新关联,EpicGame会给你发邮箱加入开发者team。)
点击GitHub头像,左下角说明已经加入了ue4的开发者team,可以访问ue4的私有库.
2.选择对应的版本下载即可。在中国大陆地区不建议使用git clone的方式,建议使用下载压缩包
git clone -b v4.27.2 https://github.com/EpicGames/UnrealEngine.git
3.代码下载完成后,进行解压缩。
修改Setup.bat文件,搜索set PROMPT_ARGUMENT=–prompt ,在其后面增加如下
set PROMPT_ARGUMENT=--prompt --cache=D:\uedepTmpLinux --threads=40 --exclude=iOS --exclude=Android --exclude=Win32 --exclude=osx32 --exclude=osx64
根据需求进行修改,这个代码是开启多线程,多缓存,排除不需要的依赖
点击Setup.bat,等待一段时间,差不多一个小时左右,主要依赖网络的速度。
4.点击GenerateProjectFiles.bat,生成UE4.sln解决方案
5.打开UE4.sln,选择如下方式,进行编译,差不多需要40分钟左右,具体依赖于电脑的配置。
6.编译完成后,选择UnrealVersionSelector-Win64-Shipping.exe,进行注册
二.Demo的编译与打包
7.选择项目进行编译,该demo采用插件的方式,开发了grpc client,可以在游戏的过程中发送grpc请求。
git clone https://github.com/vizor-games/InfraworldRuntimeExample.git
选中InfraworldDemo.uproject,右键选择下图所示的1,即可生成解决方案,选择2可以进行引擎的切换
8.编译InfraworldRuntimeExample,需要把插件放在plugins目录下,也可以下载使用预先编译好的插件。
git clone https://github.com/vizor-games/InfraworldRuntime.git
选择如下编译方式,进行编译
9.编译完成,具体如下所示(没啥事不要总是点击重新编译,这个会花费很多时间的)
10.Windows平台打包
-
按照下图所示之后,然后选择文件夹,如WindowsPackage
点击InfraworldDemo.exe即可运行。
三.Linux版本的编译与打包
11.UE4打包Linux版本的grpc库
在讨论这个问题的时候,并不是说把grpc版本下载下载,直接使用cmake的方式进行编译,这个是常规C++的项目,进行的操作,我们采用的是UE4加载grpc的方式,需要按照规则进行处理。
下载如下代码
git clone https://github.com/vizor-games/InfraworldRuntime.git
安装需要有些编译的组件
安装m4
wget http://mirrors.kernel.org/gnu/m4/m4-1.4.13.tar.gz
tar -xzvf m4-1.4.13.tar.gz \
cd m4-1.4.13
./configure –-prefix=/usr/local
make &&sudo make install
安装autoconf
wget http://mirrors.kernel.org/gnu/autoconf/autoconf-2.65.tar.gz
tar -xzvf autoconf-2.65.tar.gz
cd autoconf-2.65
./configure –prefix=/usr/local
make && sudo make install
安装automake
wget http://mirrors.kernel.org/gnu/automake/automake-1.11.tar.gz
tar xzvf automake-1.11.tar.gz
cd automake-1.11 \
./configure –-prefix=/usr/local
make && sudo make install
安装libtool
wget http://mirrors.kernel.org/gnu/libtool/libtool-2.2.6b.tar.gz
tar xzvf libtool-2.2.6b.tar.gz
cd libtool-2.2.6b
./configure –prefix=/usr/local
make && sudo make install
安装golang
wget -c https://dl.google.com/go/go1.17.8.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local
vi /etc/profile
#添加路径
export PATH=$PATH:/usr/local/go/bin
#保存之后,让其生效
source /etc/profile
#验证golang环境是搭建好
go version 或者go env
安装完成后修改 Setup.sh代码
执行 ./Setup.sh ,会进行代码下载以及编译。(注意grpc源码下载以及编译问题)
等待执行完成,进行编译后,将会生成如下所示。
提供给外部使用的Linux版本的grpc的库如下所示,只有这15个库,多余的话,可能会产生重定义的情况
12.打包Linux版本的demo,需要依赖windows版本编译出来的UEditor出现的图形界面(UBT命令行也可以编译),进行编译
选择对应的文件夹,然后开始打包
四.报错处理
1.遇到如下错误,是由于代码是从windows上下载下来的
.ibtoolize: error: AC_CONFIG_MACRO_DIRS([m4]) conflicts with ACLOCAL_AMFLAGS=-I m4
可以输入如下命令:
find . -type f -print0 | xargs -0 dos2unix
参考连接2
2.遇到如下报错
Syntax error: "(" unexpected
可以采用
sudo dpkg-reconfigure dash
3.有时候编译的时候,可能会将部分warning提示error,导致无法进行进行编译可以在下面的build.cs中增加
bEnableUndefinedIdentifierWarnings = false;
如果还有提示错误,可以考虑将部分warning禁用,增加如下代码,建议将其封装成一个头文件,让plugins下面的头文件,依赖该头文件,可以禁用错误。
/*
* Copyright 2018 Vizor Games LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the
* License for the specific language governing permissions and limitations
* under the License.
*/
// Disable some warnings in GRPC
#if PLATFORM_WINDOWS
#pragma warning(push)
#pragma warning (disable : 4125)// decimal digit terminates...
#pragma warning (disable : 4647)// behavior change __is_pod...
#pragma warning (disable : 4668)// 'symbol' is not defined as a preprocessor macro...
#pragma warning (disable : 4456)// declaration of 'size' hides previous local declaration
#pragma warning (disable : 4577)// 'noexcept' used with no exception handling mode specified
#pragma warning (disable : 4946)// reinterpret_cast used between related classes
#pragma warning (disable : 4005)// 'TEXT': macro redefinition
#pragma warning (disable : 4582)// constructor is not implicitly called
#pragma warning (disable : 4583)// destructor is not implicitly called
#pragma warning (disable : 4800)// Implicit conversion from 'type' to bool. Possible information loss
#ifdef WINDOWS_PLATFORM_TYPES_GUARD
#pragma warning(push)
#include "Windows/HideWindowsPlatformTypes.h"
#endif
#elif PLATFORM_COMPILER_CLANG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundef"
#pragma clang diagnostic ignored "-Wshadow"
#endif
4.遇到符号重定义,可以查看是哪些库函数出现了重定义
切换路径到库所在的路径下面
nm -A * 2>/dev/null | grep "T BN_value_one"