1

So I am using a game engine creation tutorial series on youtube by The Cherno. When we implemented logging into the project, we used a git repo spdlog (https://github.com/gabime/spdlog). Basically, when I tried compiling, I got two three errors:

2>SandboxApp.obj : error LNK2001: unresolved external symbol "private: static class std::shared_ptr Hazel::Log::s_CoreLogger" (?s_CoreLogger@Log@Hazel@@0V?$shared_ptr@Vlogger@spdlog@@@std@@A)

2>SandboxApp.obj : error LNK2001: unresolved external symbol "private: static class std::shared_ptr Hazel::Log::s_ClientLogger" (?s_ClientLogger@Log@Hazel@@0V?$shared_ptr@Vlogger@spdlog@@@std@@A)

2>C:\code\repos\Hazel\Hazel\bin\Debug-x64\Sandbox\Sandbox.exe : fatal error LNK1120: 2 unresolved externals

I have my own git repo if you want to check it out, https://github.com/glebnersisyan/HazelFollow/ otherwise, these are the problematic files:

Log.h:

#pragma once

#include <memory>
#include "Core.h"
#include "spdlog/spdlog.h"

namespace Hazel {
    class HAZEL_API 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; }
    private:
        static std::shared_ptr<spdlog::logger> s_CoreLogger;
        static std::shared_ptr<spdlog::logger> s_ClientLogger;
    };
}

and Log.cpp:

#include "Log.h"

namespace Hazel {

    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%$");
    }

}
Gleb
  • 11
  • 1
  • Did you raise an issue in the main repo of this project? – kiner_shah Dec 27 '21 at 07:39
  • @kiner_shah what do you mean? – Gleb Dec 27 '21 at 22:41
  • What is your ask? Do you want to resolve this linker issue? If yes, please provide some more details - which compiler, OS, platform you are compiling for? – kiner_shah Dec 28 '21 at 06:30
  • yes, I really want to resolve the linker issue, I am on windows 11 and I use visual studio 2019. Lastest SDK and C++20. – Gleb Dec 28 '21 at 21:43
  • ***error LNK2001: unresolved external symbol*** This is a linker issue. You may need to check your include and library paths. – kiner_shah Dec 29 '21 at 13:48
  • that would make sense, except I get that error even if I comment out entire Log.cpp file and get rid of any references. This is really weird, the include and lib paths are all fine – Gleb Dec 29 '21 at 22:19
  • Log seems to be a singleton class, but you are not making the constructor as private - note that compiler will assume a default constructor if you don't specify one explicitly. Also, your design is weird, you make a public static Init method but there is no guarantee that the user of this class will call Init first and simply can start using e.g. GetCoreLogger. – kiner_shah Dec 30 '21 at 05:57
  • Assuming that the user does call Init() before anything, and I marked the constructor as private, what could be the issue here. Because it still doesn't work. PS: I am not that advanced and am still learning so I apologize if I might not fully understand at first. – Gleb Dec 31 '21 at 06:36
  • You may want to refer: https://stackoverflow.com/a/13431981 – kiner_shah Dec 31 '21 at 07:31

0 Answers0