AnKor
Topic Author
Posts: 21
Joined: 22 Jul 2022, 16:14

Inline enum reflection causes linker error

14 Oct 2022, 10:27

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@?$TypeEnumFiller@W4TestEnum@Test@@@Noesis@@SAXAEAV?$TypeEnumCreator@W4TestEnum@Test@@@2@@Z) already defined in ***.obj
error LNK2005: "public: static class Noesis::TypeEnum const * __cdecl Noesis::TypeEnumFiller<enum Test::TestEnum>::GetType(void)" (?GetType@?$TypeEnumFiller@W4TestEnum@Test@@@Noesis@@SAPEBVTypeEnum@2@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.
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: Inline enum reflection causes linker error

14 Oct 2022, 10:43

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?
 
AnKor
Topic Author
Posts: 21
Joined: 22 Jul 2022, 16:14

Re: Inline enum reflection causes linker error

14 Oct 2022, 10:57

Who is online

Users browsing this forum: No registered users and 101 guests