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

425 阅读1分钟

在使用protobuf v22.0+在unreal5 C++内使用时,因为abseil-cpp存在宏定义冲突,导致编译失败

561cb1b3250ef21bb11522ab71aa2237_4858642f9c054d24b19a6b2b1c2267b7.png google搜索后得知了原因,参考下面的两个链接 protobuf github issues ABSEIL-CPP、ABSL 与 ABSEIL-CPP、UNREAL5 项目中的 ABSL 发生第三方冲突 ·问题 #16450 ·协议缓冲区/protobuf 虚幻论坛 forums.unrealengine.com/t/abseil-cp… 最终原因是:函数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

修改后的仓库参考

github.com/RSJWY/Proto…

gitee.com/RSJWY/proto…