Solution to TetrahedronKey<true> explicit specialization and implicit instantiation errors

Hello everyone,

I think this solution is for a nich problem exiting for years (first post I found about this problem was from 2022).

Sometimes, when you compile Unreal Engine 5 on Linux, you get these errors :

[917/3988] Compile Module.GeometryAlgorithms.1.cpp
In file included from ../Plugins/Runtime/GeometryProcessing/Intermediate/Build/Linux/x64/UnrealEditor/Development/GeometryAlgorithms/Module.GeometryAlgorithms.1.cpp:26:
/home/[user]/Téléchargements/UnrealEngine-5.3.2/Engine/Plugins/Runtime/GeometryProcessing/Source/GeometryAlgorithms/Private/ThirdParty/GTEngine/Mathematics/GteTetrahedronKey.cpp:78:27: error: explicit specialization of 'TetrahedronKey' after instantiation
    TetrahedronKey<true>::TetrahedronKey(int v0, int v1, int v2, int v3)
                          ^
/home/[user]/Téléchargements/UnrealEngine-5.3.2/Engine/Plugins/Runtime/GeometryProcessing/Source/GeometryAlgorithms/Private/ThirdParty/GTEngine/Mathematics/GteTSManifoldMesh.cpp:73:26: note: implicit instantiation first required here
    TetrahedronKey<true> skey(v0, v1, v2, v3);
                         ^

The solution is to add these four lines :

    template<> TetrahedronKey<true>::TetrahedronKey();
    template<> TetrahedronKey<true>::TetrahedronKey(int v0, int v1, int v2, int v3);
    template<> TetrahedronKey<false>::TetrahedronKey();
    template<> TetrahedronKey<false>::TetrahedronKey(int v0, int v1, int v2, int v3);

at the end of GteTehradronKey.h (same path as in the error message) inside the « if !defined(MSWINDOWS) » condition :

#if !defined(__MSWINDOWS__)
    // Apple LLVM 6.1.0 (clang-602.0.49) correctly requires these declarations
    // to occur before the definition in GteTetrahedronKey.cpp.  From the C++
    // specification:
    //    An explicit specialization of a static data member of a template is
    //    a definition if the declaration includes an initializer; otherwise,
    //    it is a declaration.
    // If these declarations are exposed for MSVS 2013, the compiler generates
    // error C2086, claiming that this is a definition (rather than a
    // declaration) and the cpp file has a redefinition.
    template<> std::array<int, 3> const TetrahedronKey<false>::oppositeFace[4];
    template<> std::array<int, 3> const TetrahedronKey<true>::oppositeFace[4];

    -> LINES GO HERE ! <-

#endif

From what I have seen in the repo, it can happen with version from 5.3 to 5.5.
So I hope it could help.

1 Like