abseil-cpp, absl in thirdparty redefinition error

i 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


Error C2373 ‘absl::container_internal::node_type’: redefinition; different type modifiers TestProtoForUnreal C:\Users\blackstorm_kdongin\Documents\Unreal Projects\TestProtoForUnreal\Source\ThirdParty\abseilcpp\absl\container\internal\btree.h 1653

it seems that absl\container\internal\btree.h causes that error.
i assume that it conflicts with another absl\btree.h included unreal engine 5 some where.
i found out several same abseil in unreal engine 5.
could you fix or recommend a workaround???

I have encountered another problem and I am not sure if it will be helpful to you

  • protobuf version 3.26.1 (ver 2024-04)
  • Unreal Engine version 5.3
  • vs2022 community

Reason:
The function verify() defined in the absl/container/internal/btree. h and absl/container/internal/btree. container.h files conflicts with the verify(expr) macro defined in UE5.

Solution:
In the context of function definition, cancel the macro definition of UE.

This is the code that I have personally modified, and there may be other ways to modify it.

  1. Around line 1579 of the btree.h file, after modification:
#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
  1. Around line 2610 of the btree.h file, after modification:
#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
  1. Around line 225 of the btree_container.h file, after modification:
#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

Hope it’s helpful
Best wishes

3 Likes

I am using UE5.3.2,threepotato’s solution could work if you are building a standalone application,but in my case I was building a plugin,it works fine during development,but would result in a failure if you try to package your plugin.so I tried a more aggressive way: I just delete thost two verify functions,they seems to be for test only.Also I uploaded the lib to github with some building instructions.

Hope this can be helpful.