So I have a really simple log class using spdlog.
The Log.h file looks as following:
#pragma once
#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_color_sinks.h"
namespace Engine {
class Log
{
public:
static void Init();
static std::shared_ptr<spdlog::logger>& GetLogger() { return m_ELogger; };
private:
static std::shared_ptr<spdlog::logger> m_ELogger;
};
}
#ifdef _DEBUG
#define EN_ERROR(...) ::Engine::Log::GetLogger()->error(__VA_ARGS__)
#define EN_WARN(...) ::Engine::Log::GetLogger()->warn(__VA_ARGS__)
#define EN_INFO(...) ::Engine::Log::GetLogger()->info(__VA_ARGS__)
#define EN_TRACE(...) ::Engine::Log::GetLogger()->trace(__VA_ARGS__)
#else
#define EN_ERROR(x)
#define EN_WARN(x)
#define EN_INFO(x)
#define EN_TRACE(x)
#endif
and the Log.cpp file looks like this:
#include "Log.h"
namespace Engine {
void Log::Init()
{
spdlog::set_pattern("[%H:%M:%S] [%n]: %v");
m_ELogger = spdlog::stdout_color_mt("ENGINE");
m_ELogger->set_level(spdlog::level::trace);
m_ELogger->info("Logger initialized");
}
}
And my calling code in a different file where Log.h is included looks like this:
int main() {
Engine::Log::Init();
int a = 55;
EN_ERROR("asdf {0}", a);
}
It says unresolved external symbol: private: static class std::shared_ptr>class spdlog::logger> Engine::Log::m_ELogger. I know what this error means and researched quite a bit and also tried some things but I just cant get my head around why this isnt working. The declaration is there, the defition is there. Everything is there to make the linker happy.