How to Use spdlog with Visual Studio: Complete Setup Guide

To use spdlog with Visual Studio, add the include/ directory to your project's Additional Include Directories, enable C++11 or later in the compiler settings, and include <spdlog/spdlog.h> to begin logging immediately with the global API.

The gabime/spdlog repository provides a fast, header-only C++ logging library that integrates seamlessly with Microsoft Visual Studio. Because spdlog relies on C++11 features and bundles the fmt library for formatting, it works out of the box with MSVC toolsets from Visual Studio 2015 and later. You can consume spdlog as a header-only library for instant integration, or compile it as a static/shared library for faster build times in large projects.

Installation and Project Setup

Header-Only vs. Compiled Library Mode

spdlog offers two consumption modes in Visual Studio. Header-only mode requires only that you copy the include/spdlog folder from the repository into your project and point the compiler to it. This is the fastest way to start logging because implementations are inlined at compile time. Alternatively, compiled library mode requires building spdlog separately (using CMake) and linking the resulting .lib file, which reduces compilation overhead in large codebases.

To begin with header-only mode, download the latest release and place the include folder in your solution directory. In include/spdlog/spdlog.h, you will find the central global API exposing functions like spdlog::info() and spdlog::error().

Configuring Include Directories

Open your Visual Studio project properties and navigate to C/C++ > General. Add the path to the spdlog include directory in Additional Include Directories. For example, if you placed spdlog in a third_party folder, add $(SolutionDir)third_party\spdlog\include.

Because spdlog bundles the fmt library inside include/spdlog/fmt, you do not need to download fmt separately when using header-only mode. The bundled headers are automatically referenced when you include spdlog components.

Visual Studio Compiler Configuration

Enabling C++11 or Later

spdlog requires C++11 support, which is enabled by default in Visual Studio 2015 and later. Verify your project uses a modern toolset by checking Configuration Properties > General > Platform Toolset (select v140 or later). Under C/C++ > Language, ensure C++ Language Standard is set to ISO C++11 Standard (/std:c++11) or newer.

Matching the Runtime Library

If you build spdlog as a compiled library, you must match the Runtime Library settings between spdlog and your project to avoid linker errors. In C/C++ > Code Generation, set Runtime Library to match how you built spdlog:

  • /MD for Multi-threaded DLL (Release)
  • /MDd for Multi-threaded Debug DLL (Debug)
  • /MT for Multi-threaded (Release static)
  • /MTd for Multi-threaded Debug (Debug static)

Mismatched runtimes (e.g., linking an /MD built spdlog with an /MT project) will cause unresolved external symbol errors during linking.

Logging Implementation Examples

Once your include paths are configured, you can implement various logging patterns by including specific headers from the include/spdlog directory.

Basic Global Logger (Header-Only)

Include <spdlog/spdlog.h> to use the global logger, which writes to stdout by default:

#include "spdlog/spdlog.h"

int main()
{
    // Simple logging using the global registry
    spdlog::info("Hello from spdlog in Visual Studio!");
    spdlog::warn("A warning with a number: {}", 42);

    // Customize output pattern with timestamp, level, and thread ID
    spdlog::set_pattern("[%Y-%m-%d %H:%M:%S] [%^%l%$] [thread %t] %v");
    spdlog::set_level(spdlog::level::debug);   // Enable debug output
    spdlog::debug("Debug message – now visible");
}

Color Console Output

For color-enabled console logging that works in the Visual Studio terminal and Debug output window, include <spdlog/sinks/stdout_color_sinks.h> and instantiate stdout_color_mt:

#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_color_sinks.h"

int main()
{
    // Create a multi-threaded color console logger named "console"
    auto console = spdlog::stdout_color_mt("console");
    console->info("Info message in the Visual Studio terminal");
    console->error("Error message – appears in red");
}

Rotating File Sinks

To create logs that rotate when they reach a specific size, include <spdlog/sinks/rotating_file_sink.h> and use rotating_logger_mt:

#include "spdlog/spdlog.h"
#include "spdlog/sinks/rotating_file_sink.h"

int main()
{
    // 5 MiB per file, keep 3 rotated logs
    auto rotating = spdlog::rotating_logger_mt(
        "rotating", "logs/app.log", 5 * 1024 * 1024, 3);

    rotating->info("First entry in rotating log");
    rotating->warn("A warning that survives rotation");
}

Asynchronous Logging

For high-performance applications, include <spdlog/async.h> and create an asynchronous logger with a background thread pool:

#include "spdlog/spdlog.h"
#include "spdlog/async.h"
#include "spdlog/sinks/basic_file_sink.h"

int main()
{
    // Thread pool with queue size 8192 and 2 worker threads
    spdlog::init_thread_pool(8192, 2);
    
    auto async_file = spdlog::create_async<spdlog::sinks::basic_file_sink_mt>(
        "async_file", "logs/async.log");

    async_file->info("Logging from an async logger without blocking the main thread");
}

Building spdlog as a Compiled Library

If you prefer not to use the header-only mode, you can generate a Visual Studio solution using the CMake file provided in example/CMakeLists.txt. Open a Developer Command Prompt, navigate to the spdlog root, and run:

cmake -B build -S . -DSPDLOG_BUILD_SHARED=OFF
cmake --build build --config Release

This produces a static library (spdlog.lib) that you must link in your project by adding the library path to Linker > General > Additional Library Directories and adding spdlog.lib to Linker > Input > Additional Dependencies.

Summary

  • Header-only integration requires only adding include/spdlog to Additional Include Directories; no separate linking is needed because fmt is bundled in include/spdlog/fmt.
  • Compiled mode requires building spdlog via CMake (see example/CMakeLists.txt), then matching your project's Runtime Library setting (/MD, /MDd, /MT, /MTd) to avoid linker errors.
  • Core functionality resides in include/spdlog/spdlog.h, with specialized sinks in include/spdlog/sinks/ and async support in include/spdlog/async.h.
  • Visual Studio 2015 and later are fully supported with C++11 or newer standards enabled.

Frequently Asked Questions

Does spdlog work with Visual Studio 2022?

Yes, spdlog is fully compatible with Visual Studio 2022, 2019, and 2017. The library requires C++11 support, which has been available in MSVC since Visual Studio 2015. Simply ensure your project targets a modern Platform Toolset (v140 or later) and uses a C++ standard of at least C++11.

Should I use header-only or compiled spdlog in Visual Studio?

Use header-only mode for small to medium projects where compile times are manageable and you want the simplest setup. Use compiled mode for large codebases where reducing compilation overhead is critical. In compiled mode, you must link against the spdlog.lib file and ensure your Runtime Library settings match exactly.

How do I fix linker errors when using spdlog with Visual Studio?

Linker errors typically occur from mismatched Runtime Library settings. Check Project Properties > C/C++ > Code Generation > Runtime Library and ensure it matches the setting used when spdlog was built (/MD for DLL, /MT for static). If using header-only mode, ensure you are not accidentally linking against a precompiled spdlog library from an earlier attempt.

Can spdlog output to the Visual Studio Debug Output window?

Yes, when using console sinks like stdout_color_mt or stderr_color_mt from include/spdlog/sinks/stdout_color_sinks.h, output appears in both the console and the Visual Studio Output window when running under the debugger. For exclusive Debug window output, you can create a custom sink using OutputDebugString from the Windows API, though the standard console sinks are sufficient for most debugging workflows.

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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →