AnKor
Topic Author
Posts: 14
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> &)" ([email protected][email protected]@[email protected]@@[email protected]@[email protected]@[email protected]@@[email protected]@Z) already defined in ***.obj
error LNK2005: "public: static class Noesis::TypeEnum const * __cdecl Noesis::TypeEnumFiller<enum Test::TestEnum>::GetType(void)" ([email protected][email protected]@[email protected]@@[email protected]@[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.
 
User avatar
jsantos
Site Admin
Posts: 3594
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: 14
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 3 guests