Search code examples
c++cmakefmtspdlog

spdlog header-only with external fmt. spdlog error: 'internal': is not a member of 'fmt'


I am using header-only spdlog as cmake's external project.

find_program(GIT_EXECUTABLE git)

ExternalProject_Add(
    spdlog
    PREFIX ${CMAKE_BINARY_DIR}/vendor/spdlog
    GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
    GIT_TAG "v1.6.1"
    TIMEOUT 10
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ""
    INSTALL_COMMAND ""
    UPDATE_COMMAND ""
)

To link the external fmt library to spdlog, the following was added.

add_subdirectory(fmt EXCLUDE_FROM_ALL)
...
target_link_libraries(myProject
        fmt::fmt
    )

It is executed in this state. but if I add the following code to use external fmt, a compile error occurs.

#define SPDLOG_FMT_EXTERNAL   // If I add this code I get an error.
#include <spdlog/spdlog.h>

The error message is as follows.

myproject\build\x64-Debug\vendor\spdlog\src\spdlog\include\spdlog\details\fmt_helper.h(40): error C2039: 'internal': is not a member of 'fmt'

I think spdlog needs to be installed to use an external fmt, not a bundle, but I am not doing that. When I install spdlog with "ExternalProject_Add", I think I need to do something extra, but I don't know what it is.

I found an option that seems to be related to this in spdlog/CMakeLists.txt

option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)

I tried the following method to change "SPDLOG_FMT_EXTERNAL" to "ON", but the problem remains the same. I am not sure if this is the right way and a suitable solution. thanks.

ExternalProject_Add(
    spdlog
    PREFIX ${CMAKE_BINARY_DIR}/vendor/spdlog
    GIT_REPOSITORY "https://github.com/gabime/spdlog.git"
    GIT_TAG "v1.6.1"
    TIMEOUT 10
    CONFIGURE_COMMAND ""
    CMAKE_ARGS "-DSPDLOG_FMT_EXTERNAL=ON -DDSPDLOG_FMT_EXTERNAL:string=ON"
    BUILD_COMMAND ""
    INSTALL_COMMAND ""
    UPDATE_COMMAND ""
)

Solution

  • This has been fixed in spdlog version 1.7: https://github.com/gabime/spdlog/releases/tag/v1.7.0:

    Support for using external fmt version 7.x