我有2个项目的解决方案:
- 静态库(Almond)
- 使用该静态库的项目(沙盒)
我正在观看和跟随Cherno的Game Engine Series,除了我使用C++20模块。他通过git submodule add
添加spdlog
。我做了同样的事情。然后我在Almond项目中将$(SolutionDir)Almond\vendor\spdlog\include
添加到Additional Include Directories
。
这个库构建得很好(有一堆来自sal.h
的宏重定义警告)。当我尝试构建沙箱时,我没有收到任何警告,只有这些错误:
Severity Code Description Project File Line Suppression State
Error LNK1120 4 unresolved externals Sandbox C:\source\Almond\bin\Debug-x64\Sandbox\Sandbox.exe 1
Error LNK2019 unresolved external symbol __imp_MapViewOfFileNuma2 referenced in function MapViewOfFile2 Sandbox C:\source\Almond\Sandbox\Almond.lib(stdout_color_sinks.h_D07BG2BYL2KQ67JA.obj) 1
Error LNK2001 unresolved external symbol __imp_MapViewOfFileNuma2 Sandbox C:\source\Almond\Sandbox\Almond.lib(spdlog.h_UEKL7NPFP4GR8605.obj) 1
Error LNK2001 unresolved external symbol "private: static class std::shared_ptr<class spdlog::logger> Almond::Log::s_CoreLogger" (?s_CoreLogger@Log@Almond@@0V?$shared_ptr@Vlogger@spdlog@@@std@@A::<!Log>) Sandbox C:\source\Almond\Sandbox\Almond.lib(Log.ixx.obj) 1
Error LNK2001 unresolved external symbol "private: static class std::shared_ptr<class spdlog::logger> Almond::Log::s_ClientLogger" (?s_ClientLogger@Log@Almond@@0V?$shared_ptr@Vlogger@spdlog@@@std@@A::<!Log>) Sandbox C:\source\Almond\Sandbox\Almond.lib(Log.ixx.obj) 1
Error LNK2001 unresolved external symbol "char const * const spdlog::details::os::default_eol" (?default_eol@os@details@spdlog@@3QEBDEB) Sandbox C:\source\Almond\Sandbox\Almond.lib(Log.ixx.obj) 1
相关代码
日志ixx(杏仁色):
export module Log;
import <memory>;
import <spdlog/spdlog.h>;
import <spdlog/sinks/stdout_color_sinks.h>;
export namespace Almond {
class Log {
private:
static std::shared_ptr<spdlog::logger> s_CoreLogger;
static std::shared_ptr<spdlog::logger> s_ClientLogger;
public:
static void Init() {
spdlog::set_pattern("%^[%T] %n: %v%$");
// Create multithreaded loggers
s_CoreLogger = spdlog::stdout_color_mt("ALMOND", spdlog::color_mode::always);
s_CoreLogger->set_level(spdlog::level::trace);
s_ClientLogger = spdlog::stdout_color_mt("APP", spdlog::color_mode::always);
s_ClientLogger->set_level(spdlog::level::trace);
}
inline static std::shared_ptr<spdlog::logger>& GetCoreLogger() { return s_CoreLogger; }
inline static std::shared_ptr<spdlog::logger>& GetClientLogger() { return s_ClientLogger; }
};
}
入口点.ixx(杏仁色):
export module EntryPoint;
import Application;
import Log;
#ifdef ALMOND_PLATFORM_WINDOWS
export int main(int argc, char** argv) {
Almond::Log::Init();
auto app = Almond::CreateApplication();
app->Run();
delete app;
}
#endif
Main.cpp(沙盒):
import Almond;
class Sandbox : public Almond::Application {
public:
Sandbox() {}
~Sandbox() {}
};
Almond::Application* Almond::CreateApplication() {
return new Sandbox();
}
1条答案
按热度按时间gcxthw6b1#
使用该静态库的项目
这个项目是编译为共享(DLL)还是静态(.lib)库?我假设您将可执行文件与“使用该静态库的项目”链接。如果是这样,您需要从该项目启用符号可见性。
我不使用VS,但是CMake可以用GenerateExportHeader很好地处理这个问题,你需要在你的类中包含
__decl(dllexport)
和__decl(dllimport)
,或者公开所有的符号可见性。默认情况下,Windows将所有符号设置为私有,而UNIX变体将它们设置为公共。