Page 1 of 1

Inline enum reflection causes linker error

Posted: 14 Oct 2022, 10:27
by AnKor
Hi!
Could you advice what am I doing wrong?

Here's the header file:
namespace Test
{
	enum class TestEnum
	{
		A = 0,
		B = 1
	};
}

NS_IMPLEMENT_INLINE_REFLECTION_ENUM(Test::TestEnum)
{
	NsVal("A", Test::TestEnum::A);
	NsVal("B", Test::TestEnum::B);
}
And here's what I get from the linker:
error LNK2005: "public: static void __cdecl Noesis::TypeEnumFiller<enum Test::TestEnum>::Fill(class Noesis::TypeEnumCreator<enum Test::TestEnum> &)" (?Fill@[email protected]@Test@@@Noesis@@SAXAEAV?$Ty[email protected]@Test@@@2@@Z) already defined in ***.obj
error LNK2005: "public: static class Noesis::TypeEnum const * __cdecl Noesis::TypeEnumFiller<enum Test::TestEnum>::GetType(void)" (?GetType@[email protected]@Test@@@Noesis@@[email protected]@XZ) already defined in ***.obj
Enums work without an issue if I separate their declaration and implementation, but I'd like to use NS_IMPLEMENT_INLINE_REFLECTION_ENUM to keep them in one place.

Re: Inline enum reflection causes linker error

Posted: 14 Oct 2022, 10:43
by jsantos
It seems there is a problem when using that macro in headers included more than once. The following patch fixes the problem:
Index: ReflectionImplementEnum.h
===================================================================
--- ReflectionImplementEnum.h	(revision 11568)
+++ ReflectionImplementEnum.h	(working copy)
@@ -41,11 +41,11 @@
 ///
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 #define NS_IMPLEMENT_REFLECTION_ENUM2(T, name) \
-    const Noesis::TypeEnum* Noesis::TypeEnumFiller<T>::GetType() \
+    inline const Noesis::TypeEnum* Noesis::TypeEnumFiller<T>::GetType() \
     { \
         return Noesis::TypeEnumHelper<T>::GetType(name); \
     } \
-    void Noesis::TypeEnumFiller<T>::Fill(Noesis::TypeEnumCreator<T>& helper)
+    inline void Noesis::TypeEnumFiller<T>::Fill(Noesis::TypeEnumCreator<T>& helper)
 
 #define NS_IMPLEMENT_REFLECTION_ENUM1(T) NS_IMPLEMENT_REFLECTION_ENUM2(T, #T)
Could you please report this in the tracker?

Re: Inline enum reflection causes linker error

Posted: 14 Oct 2022, 10:57
by AnKor