How to Install spdlog on Windows: Header-Only and Compiled Library Guide
You can install spdlog on Windows either as a header-only library by copying the include/spdlog directory to your project, or as a compiled library using CMake and Visual Studio to reduce compile times and binary size.
The gabime/spdlog repository provides multiple installation paths for Windows developers. Whether you need a quick drop-in solution or a performant compiled binary, the library supports both approaches with full compatibility for MSVC 2013 and newer. This guide covers the exact steps needed to integrate spdlog into your Windows C++ project based on the official source code structure.
Installation Methods Overview
spdlog supports two primary installation modes on Windows. The header-only approach requires no building—simply copy the include/spdlog directory into your project. The compiled library approach, recommended for production use, involves generating a Visual Studio solution with CMake and building spdlog.lib (or spdlog.dll) to link against your application.
Option 1: Header-Only Installation (Quickest)
The header-only method is the fastest way to start logging. It requires no build system configuration and works immediately with any C++11-compatible compiler on Windows.
Manual Setup Steps
- Download or clone the repository from
https://github.com/gabime/spdlog.git - Copy the entire
include/spdlogdirectory to your project's include path or your compiler's system include directory - Add the parent directory of
spdlogto your compiler's include search path - Compile with MSVC 2013 or newer, or using the Cygwin toolchain
No linking step is required. The implementation resides entirely in the headers located in include/spdlog/spdlog.h and its dependencies.
Option 2: Compiled Library Installation (Recommended)
Building spdlog as a compiled library significantly reduces compile times for downstream projects and produces smaller binaries. This is the recommended approach for production Windows applications.
Building with CMake and Visual Studio
From the root of the cloned repository, execute these commands in a Developer Command Prompt:
# Clone the source
git clone https://github.com/gabime/spdlog.git
cd spdlog
# Create a build directory
mkdir build && cd build
# Generate Visual Studio solution (adjust generator for your version)
cmake .. -G "Visual Studio 16 2019" -A x64
# Optional: Build as shared library (DLL) instead of static
# cmake .. -G "Visual Studio 16 2019" -A x64 -DBUILD_SHARED_LIBS=ON
# Build the library
cmake --build . --config Release
The build process uses the root CMakeLists.txt to configure the project. Upon completion, you will find spdlog.lib (or spdlog.dll and its import library) in the build directory.
Linking the Library
After building, configure your project to use the compiled library:
- Add the
includedirectory from the spdlog repository to your compiler's include path - Link against
spdlog.lib(add it to your linker inputs) - If you built a shared library (
-DBUILD_SHARED_LIBS=ON), ensurespdlog.dllis in your PATH or executable directory
The example example/CMakeLists.txt in the repository demonstrates how to properly consume the compiled library using find_package(spdlog REQUIRED).
Package Manager Installation (Alternative)
For automated dependency management, use these Windows package managers:
vcpkg
vcpkg install spdlog
This command fetches a pre-built binary and configures include/library paths automatically. The vcpkg portfile (vcpkg/ports/spdlog/portfile.cmake in the repository) handles the CMake configuration for you.
Conan
conan install spdlog/[*]
Conan resolves dependencies and generates the necessary configuration for your build system.
Usage Examples
Header-Only Usage
Create a main.cpp file with no additional linking required:
#include "spdlog/spdlog.h"
int main() {
spdlog::info("spdlog works on Windows – header-only!");
spdlog::warn("A warning with a number: {}", 42);
return 0;
}
Compile with: cl /std:c++11 /EHsc main.cpp /I path\to\spdlog\include
Compiled Library Usage
When using the compiled library, link against the built target:
#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
int main() {
auto console = spdlog::stdout_color_mt("console");
console->info("Compiled spdlog on Windows – ready to go!");
return 0;
}
For CMake projects, use this configuration:
cmake_minimum_required(VERSION 3.8)
project(MyApp)
find_package(spdlog REQUIRED)
add_executable(myapp main.cpp)
target_link_libraries(myapp PRIVATE spdlog::spdlog)
Summary
- Header-only installation requires copying
include/spdlogto your project and works with MSVC 2013+ without linking - Compiled library installation uses CMake to generate Visual Studio solutions, producing
spdlog.liborspdlog.dllfor faster compile times - The root
CMakeLists.txtcontrols the build process and installation targets - Package managers like vcpkg and Conan provide pre-built Windows binaries with automatic configuration
- The primary public header
include/spdlog/spdlog.hprovides the complete logging API in both installation modes
Frequently Asked Questions
Should I use header-only or compiled spdlog on Windows?
Use the compiled library for production projects to reduce compile times and binary size. Use header-only only for quick prototypes or when you cannot modify your build system to link external libraries, as the header-only mode increases compilation time for every source file that includes spdlog headers.
What Visual Studio versions are supported?
The gabime/spdlog source code supports MSVC 2013 and newer. When running CMake, specify the generator matching your installed version (e.g., "Visual Studio 16 2019" or "Visual Studio 17 2022"). The library also works with MinGW and Cygwin toolchains on Windows.
How do I link spdlog as a DLL on Windows?
Pass -DBUILD_SHARED_LIBS=ON to CMake when generating the Visual Studio solution. This creates spdlog.dll and its import library. Link against the import library in your project and ensure spdlog.dll is available in your executable's directory or system PATH at runtime.
Can I use spdlog with MinGW or Cygwin on Windows?
Yes. The header-only mode works with any C++11-compatible compiler including MinGW and Cygwin. For the compiled library, use the appropriate CMake generator (e.g., "MinGW Makefiles" or "Unix Makefiles") instead of the Visual Studio generator when building.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →