I have two projects, the first one is a dynamic library project, lets say Log
project, and there is a file:
Log.h
#pragma once
#include "Core.h"
#include "spdlog/spdlog.h"
#include <memory>
namespace Prunus{
class __declspec(dllexport) Log
{
public:
static void Init();
inline static std::shared_ptr<spdlog::logger>& GetCoreLogger() { return s_CoreLogger; }
inline static std::shared_ptr<spdlog::logger>& GetClientLogger() { return s_ClientLogger; }
static std::shared_ptr<spdlog::logger> s_CoreLogger;
static std::shared_ptr<spdlog::logger> s_ClientLogger;
};
}
while in Log.cpp
, it is:
#include "Log.h"
#include "spdlog/sinks/stdout_color_sinks.h"
namespace Prunus {
std::shared_ptr<spdlog::logger> Log::s_CoreLogger;
std::shared_ptr<spdlog::logger> Log::s_ClientLogger;
void Log::Init() {
spdlog::set_pattern("%^[%T] %n: %v%$");
s_CoreLogger = spdlog::stdout_color_mt("PRUNUS");
s_CoreLogger->set_level(spdlog::level::trace);
s_ClientLogger = spdlog::stdout_color_mt("APP");
s_ClientLogger->set_level(spdlog::level::trace);
}
}
And I tried to invoke the Log::Init() in Log project it self, it can work. But when I reference it in another project which references on Log project, it throws error like:
Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "public: static class std::shared_ptr<class spdlog::logger> Prunus::Log::s_CoreLogger" (?s_CoreLogger@Log@Prunus@@2V?$shared_ptr@Vlogger@spdlog@@@std@@A) Sandbox F:\code\Prunus\Prunus\Sandbox\SandboxApplication.obj 1
Not sure whether there are additional settings I missed in visual studio 2022
I tried to use the Log::Init() inside the Log project, it can work, but it can not while referencing outside the project. What I want is to reference it outside the Log project.