c++ - 使用 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++ 新手。
解决方案
一切都在 Thigre 命名空间下,除了 Log.h,它出于某种原因在 Hazel 命名空间下。可能会解决你的问题。确保在复制和粘贴代码时更改所有内容。
推荐阅读
- html - 如何调整包括图像在内的 webview 内容的大小以适应水平边界
- css - 将动画 SVG 停止到屏幕上的某个位置
- node.js - 亚马逊 Alexa 的技能购买追加销售不起作用
- matrix - 将列向量转换为R中矩阵的对角线?
- c# - Xamarin 表单 - 文件系统
- c# - WebHost 重新启动并丢失令牌验证
- angular - 如何将多个街道地址转换为经纬度并在 Angular 8 的谷歌地图上显示?
- python - 在 tensorflow 中训练两个连续的模型
- ios - 如何用相同的键存储int值
- python - 如何使用 python 连接到 Windows aws 虚拟机?