【问题标题】:Compile Errors When Including Boost 1.79.0 Bimap w/ Unreal 5包含带有 Unreal 5 的 Boost 1.79.0 Bimap 时的编译错误
【发布时间】:2023-01-11 12:18:52
【问题描述】:

一年多来,我一直在使用 Boost 的 Bimap 作为库存系统的基础。

typedef boost::bimap<boost::bimaps::set_of<uint32>,
    boost::bimaps::multiset_of<uint32>,
    boost::bimaps::with_info<FItemDetails>> InventoryBimap;

不过,在从 Unreal 4 更新到 Unreal 5 之后,我做了一些其他更改。我从 Boost 1.68.0 移到了 1.79.0。我从 C++17 转移到 C++20。

编辑:抱歉,我忘了包括我正在使用 Visual Studio 2022。

阻止我的游戏编译的一堆编译错误有两个来源:

1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2988: unrecognizable template declaration/definition
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(127): note: see reference to class template instantiation 'boost::detail::ptr_to_expr<T,E>' being compiled
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2059: syntax error: '<end Parse>'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2988: unrecognizable template declaration/definition
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2059: syntax error: '->'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(120): error C2238: unexpected token(s) preceding ';'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(123): error C2988: unrecognizable template declaration/definition
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(123): error C2059: syntax error: '<end Parse>'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\pointer_traits.hpp(123): error C2334: unexpected token(s) preceding '{'; skipping apparent function body

然后:

1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(397): error C2988: unrecognizable template declaration/definition
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(407): note: see reference to class template instantiation 'boost::detail::alloc_has_allocate<A>' being compiled
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(397): error C2059: syntax error: '<end Parse>'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(397): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(398): error C2988: unrecognizable template declaration/definition
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(398): error C2059: syntax error: '->'
1>H:\UnrealEngine\Engine\Source\ThirdParty\boost\boost-1_79_0\include\boost\core\allocator_access.hpp(400): error C2238: unexpected token(s) preceding ';'

对于 allocator_access.hpp 中的每个模板,都会重复第二个错误。

到目前为止,我发现的唯一短期修复方法是注释掉我项目中包含的所有 bimap。

我目前不确定如何进行,希望有人对可能发生的事情有所了解。

【问题讨论】:

    标签: c++ boost unreal-engine5


    【解决方案1】:

    所以,我找到了答案。在这里分享一下,让大家知道:

    在pointer_traits.hpp中,模板有两个作用:

            template<class O>
            static auto check(int)->result<decltype(O::pointer_to(source()))>;
    
            template<class>
            static char check(long);
    

    我突然注意到了这个名字:“检查”。

    “check”是一个虚幻宏名称,它强制虚幻引擎在调用时崩溃(除非附加了调试器)。因此,函数调用看着normal 被解释为调用 Unreal 的检查宏并导致编译失败。

    所以我不得不在整个提升过程中将“检查”重命名为其他名称。这修复了编译错误,我的库存系统又开始工作了。

    【讨论】:

    • “所以我不得不在整个提升过程中将“检查”重命名为其他名称”那永远不是解决方案。解决方案是用不卫生的宏(如“check”)隔离包含的标头。老实说,这是一种可怕的做法,您应该向他们的问题跟踪器提出问题。
    • 同时,明显的解决方法是在任何带有错误宏的内容之前包含 boost 标头(显然像 unreal 标头)
    • 看起来 Unreal 正在创建质量很差的代码。出于与上述完全相同的原因,宏通常被定义为大写;因为它们不能嵌套在命名空间中。
    • 是的,我确实同意这甚至不应该成为问题,但这是我目前能找到的唯一解决方案,我希望发布这个可以帮助其他遇到这个问题的可怜人未来。
    • 除此之外,在您建议重新排列包含之后,我确实尝试将所有 Boost 包含放在标题中。它不能解决问题。错误仍然发生。重命名仍然是我唯一可行的解​​决方案。
    【解决方案2】:

    我也遇到过这个问题,PosoKhov 的解决方案是最快、最干净的。分叉 UE 存储库和修改宏很快就变得一团糟,因为它似乎也在插件中被引用。

    【讨论】:

      猜你喜欢
      • 2012-07-28
      • 1970-01-01
      • 1970-01-01
      • 2019-05-23
      • 1970-01-01
      • 2010-09-30
      • 2018-07-20
      • 1970-01-01
      • 2013-03-23
      相关资源
      最近更新 更多