protobuf v22.0+在虚幻5中的导入问题(abseil-cpp在虚幻使用问题)

Tips:如果我的文章被vip可看,请私信联系我修改。

下面的两个链接,是参考文章

使用Protobuf+Websocket构建Unreal与Python服务器的通信_ue5 onbinarymessage()-优快云博客icon-default.png?t=O83Ahttps://blog.youkuaiyun.com/hacning/article/details/132167066

虚幻引擎随笔:接入 Google Protobuf 库 - 知乎icon-default.png?t=O83Ahttps://zhuanlan.zhihu.com/p/556147044

在protobuf v22.0+之后的版本,官方不再提供对应语言的分支,需要下载完整版进行构建。这里使用了vcpkg进行构建(会落后于gihub版本),操作相对简单,会把相关依赖导入。

因为22.0+后面abseil被整体分离,需要单独导入到unreal里。即使是把abseil导入到虚幻内,在代码编译时,会因为内部函数报错。

同时代码编译器会在cpp下产生如下警告:(这个问题可使用编辑器提示修复)

这两个问题会导致虚幻无法正确编译。到这,其实可以使用22.10版本,这个版本不需要复杂的处理,仍然可用。或者修改abseil文件,使其支持。

上面的原因,在protobuf的issue中提交过一个。但是没有解决方案ABSEIL-CPP、ABSL 与 ABSEIL-CPP、UNREAL5 项目中的 ABSL 发生第三方冲突 ·问题 #16450 ·协议缓冲区/protobuficon-default.png?t=O83Ahttps://github.com/protocolbuffers/protobuf/issues/16450最终,通过google,在虚幻论坛上搜索到了:abseil-cpp, absl in thirdparty redefinition error - Programming & Scripting - Epic Developer Community Forumsi am trying to include protobuf lastest version 3.26.1 (ver 2024-04) in unreal 5. (i am using vs2022 community) when i include protobuf using thirdparty abseil-cpp, i face compile error C2373(redefinition). like below …icon-default.png?t=O83Ahttps://forums.unrealengine.com/t/abseil-cpp-absl-in-thirdparty-redefinition-error/1794996

需要修改两个文件: btree.h和btree_container.h文件。原因是函数verify()定义在absl/container/internal/btree中。H和absl/container/internal/btree。h文件与UE5中定义的验证(expr)宏冲突。需要修改代码,在相关行上下移除相关定义

搜索相关错误代码所在行段,在前后文加上(不同版本行号可能不同)

btree.h

#ifdef verify
#undef verify
#endif
  // Verifies the structure of the btree.
  void verify() const;
#ifndef verify
#define verify(expr)			UE_CHECK_IMPL(expr)  // copy from line 221 of /Engine/Source/Runtime/Core/Public/Misc/AssertionMacros.h
#endif
#ifdef verify
#undef verify
#endif
template <typename P>
void btree<P>::verify() const {
  assert(root() != nullptr);
  assert(leftmost() != nullptr);
  assert(rightmost() != nullptr);
  assert(empty() || size() == internal_verify(root(), nullptr, nullptr));
  assert(leftmost() == (++const_iterator(root(), -1)).node_);
  assert(rightmost() == (--const_iterator(root(), root()->finish())).node_);
  assert(leftmost()->is_leaf());
  assert(rightmost()->is_leaf());
}
#ifndef verify
#define verify(expr)			UE_CHECK_IMPL(expr)  // copy from line 221 of /Engine/Source/Runtime/Core/Public/Misc/AssertionMacros.h
#endif

btree_container.h

#ifdef verify
#undef verify
#endif
  void verify() const { tree_.verify(); }
#ifndef verify
#define verify(expr)			UE_CHECK_IMPL(expr)  // copy from line 221 of /Engine/Source/Runtime/Core/Public/Misc/AssertionMacros.h
#endif

至此,修复完成。

修改后的仓库参考

https://github.com/RSJWY/ProtobufAndAbseil-Unreal5icon-default.png?t=O83Ahttps://github.com/RSJWY/ProtobufAndAbseil-Unreal5

https://gitee.com/RSJWY/protobuf-and-abseil-unreal5icon-default.png?t=O83Ahttps://gitee.com/RSJWY/protobuf-and-abseil-unreal5

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值