首页 > 解决方案 > 使用 Spdlog c++ 库无法解析的外部符号“__declspec(dllimport)

问题描述

将此库导入我的 c++ 项目时遇到此问题。当我构建 dll 解决方案时,Visual Studio 抛出错误“未解析的外部符号”,并在我删除类 Log 时消失。

日志.h:

#pragma once
#include "Core.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_color_sinks.h"

namespace Thigre {
    class THIGRE_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;
    };
}

日志.cpp:

#include "Log.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_color_sinks.h"
namespace Thigre {
    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("THIGRE");
        s_CoreLogger->set_level(spdlog::level::trace);

        s_ClientLogger = spdlog::stdout_color_mt("MOTOR");
        s_ClientLogger->set_level(spdlog::level::trace);
    }
}

我已经读过一个关于这个问题的问题,但老实说我不明白解决方案,它在下一个代码块中:链接到答案这里

#include "Log.h"

namespace Hazel {

    // declare these as part of Log!
    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%$");
    }

}

答案说将这些声明为 Log 的一部分!但我不知道这意味着什么,我是 C++ 新手。

标签: c++

解决方案


一切都在 Thigre 命名空间下,除了 Log.h,它出于某种原因在 Hazel 命名空间下。可能会解决你的问题。确保在复制和粘贴代码时更改所有内容。


推荐阅读