I have global variables that I define in the Utility namespace. This utility is included in several files and it looks like this:
#ifndef _UT_
#define _UT_
namespace UT {
std::string PLATFORM_LINUX_NAME = "linux";
std::string PLATFORM_MACOSX_NAME = "macosx";
std::string PLATFORM_WINDOWS_NAME = "windows";
#if defined(OS_WIN)
int PLATFORM = OSTYPE::PLATFORM_WINDOWS;
#elif defined(OS_LINUX)
int PLATFORM = PLATFORM_LINUX;
#elif defined(OS_APPLE)
int PLATFORM = PLATFORM_MACOSX;
#endif
};
When I include this file in for example files A.h and B.h and C.h, I'm getting a compiler warning that says:
warning LNK4006: "int UT::PLATFORM" (?PLATFORM@UT@@3HA) already defined in A.obj; second definition ignored
warning LNK4006: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > UT::PLATFORM_LINUX_NAME" (?PLATFORM_LINUX_NAME@UT@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in A.obj; second definition ignored
What is the best way that does not involve creating a class for solving this? Or is creating a UT class the only way?