簡體   English   中英

使用 Spdlog c++ 庫無法解析的外部符號“__declspec(dllimport)

[英]Unresolved external symbol "__declspec(dllimport) with Spdlog c++ library

將此庫導入我的 c++ 項目時遇到此問題。 當我構建 dll 解決方案時,Visual Studio 拋出錯誤“未解析的外部符號”,並在我刪除 class 日志時消失。

日志.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++ 新手。

一切都在 Thigre 命名空間下,除了 Log.h,它出於某種原因在 Hazel 命名空間下。 可能會解決你的問題。 確保在復制和粘貼代碼時更改所有內容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM