andre.hre
andre.hre

Reputation: 61

Visual studio not finding spdlog.lib

I've been trying to create a simple project to understand the build process on Windows. Recently, I downloaded and installed spdlog library, the folder of installation is located at

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.

Well, with this last information I created the following 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

LNK 1104: Can not open file '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.

I have 3 questions:

Update 1

I've already tried to escape the spaces in the path of spdlog, but it didn't work.

Update 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. The second installation was in Program Files, so I believe this time I used the appropriate path library: "C:/Program Files /spdlog/include".

But the problem remains.

Upvotes: 0

Views: 1909

Answers (1)

icebp
icebp

Reputation: 1709

Your build fails because you installed spdlog in a path that contains spaces. Try escaping the spaces:

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.

There are two ways of using (linking) dynamic libraries on Windows: implicit and explicit. 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).

EDIT: it turns out that debug builds of spdlog create a spdlogd.lib (notice the extra d). The author of the question had installed a debug build of the library.

Upvotes: 1

Related Questions