[英]Visual studio not finding spdlog.lib
I've been trying to create a simple project to understand the build process on Windows.我一直在尝试创建一个简单的项目来了解 Windows 上的构建过程。 Recently, I downloaded and installed spdlog library, the folder of installation is located at
最近下载安装了spdlog库,安装文件夹位于
C:\Program Files (x86)\spdlog C:\Program Files (x86)\spdlog
with the following directories:具有以下目录:
I tried to link spdlog.dll with cmake to my code, but according to this link , dll files aren't linked, the suitable procedure is to link with a.lib file.我试图将 spdlog.dll 与 cmake 链接到我的代码,但根据此链接,dll 文件未链接,合适的程序是链接 a.lib 文件。
Well, with this last information I created the following CMakeLists.txt.好吧,有了最后的信息,我创建了以下 CMakeLists.txt。
cmake_minimum_required (VERSION 3.8)
set(APPNAME DrumHero)
project($APPNAME)
#C++ version
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(SOURCES src/drumhero.cpp)
set(HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/drumhero.h)
set(DEPENDENCIES_LIBS spdlog)
link_directories("C:/Program Files (x86)/spdlog/lib")
include_directories("C:/Program Files (x86)/spdlog/include")
add_executable (${APPNAME} ${SOURCES} ${HEADERS})
target_link_libraries(${APPNAME}
PUBLIC ${DEPENDENCIES_LIBS})
set_target_properties(${APPNAME} PROPERTIES
PUBLIC_HEADER "${HEADERS}")
When I try to build it Visual studio returns the error当我尝试构建它时,Visual Studio 返回错误
LNK 1104: Can not open file 'spdlog.lib'. LNK 1104:无法打开文件“spdlog.lib”。
I concluded that my main error is related to inform cmake where is the file 'spdlog.lib', but I don't know where exactly is the error.我得出的结论是,我的主要错误与通知 cmake 文件“spdlog.lib”在哪里有关,但我不知道错误到底在哪里。
I have 3 questions:我有3个问题:
Update 1更新 1
I've already tried to escape the spaces in the path of spdlog, but it didn't work.我已经尝试转义 spdlog 路径中的空格,但没有成功。
Update 2更新 2
Some comments raised the possibility that I might be mixing x64 with x86, so I decided to reinstall spdlog, now changing the architecture to x64.一些评论提出了我可能将 x64 与 x86 混合的可能性,因此我决定重新安装 spdlog,现在将架构更改为 x64。 The second installation was in Program Files, so I believe this time I used the appropriate path library: "C:/Program Files /spdlog/include".
第二次安装是在 Program Files 中,所以我相信这次我使用了适当的路径库:“C:/Program Files /spdlog/include”。
But the problem remains.但问题依然存在。
Your build fails because you installed spdlog
in a path that contains spaces.您的构建失败,因为您将
spdlog
安装在包含空格的路径中。 Try escaping the spaces:尝试 escaping 空格:
link_directories("C:/Program\ Files\ (x86)/spdlog/lib")
As far as linking goes, on Windows, dll
files are dynamic libraries, while lib
files are static libraries.就链接而言,在 Windows 上,
dll
文件是动态库,而lib
文件是 static 库。
There are two ways of using (linking) dynamic libraries on Windows: implicit and explicit.在 Windows 上有两种使用(链接)动态库的方法:隐式和显式。 Both are documented here .
两者都记录在这里。 If you built
spdlog
as a DLL the spdlog.lib
you see is just an import library and the OS will load spdlog.dll
when your application starts (if it can find the DLL).如果您将
spdlog
构建为 DLL,那么您看到的spdlog.lib
只是一个导入库,操作系统将在您的应用程序启动时加载spdlog.dll
(如果它可以找到 DLL)。
EDIT: it turns out that debug builds of spdlog
create a spdlogd.lib
(notice the extra d
).编辑:事实证明
spdlog
的调试版本创建了一个spdlogd.lib
(注意额外的d
)。 The author of the question had installed a debug build of the library.该问题的作者已经安装了该库的调试版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.