# ${SPDLOG\_LIBRARIES} vs spdlog:spdlog

**URL:** <https://discourse.cmake.org/t/spdlog-libraries-vs-spdlog-spdlog/11632>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [September 10, 2024, 9:35am UTC](https://discourse.cmake.org/t/spdlog-libraries-vs-spdlog-spdlog/11632 "2024-09-10T09:35:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sea\_Sea](https://discourse.cmake.org/user_avatar/discourse.cmake.org/sea_sea/32/4025_2.png) [@Sea\_Sea](https://discourse.cmake.org/u/Sea_Sea)\
**Post date:** [September 10, 2024, 9:35am UTC](https://discourse.cmake.org/t/spdlog-libraries-vs-spdlog-spdlog/11632/1 "2024-09-10T09:35:18Z")

</div>

```auto

find_library(SPDLOG_LIBRARIES
    NAMES 
        spdlog
        spdlogd
    REQUIRED
)

# SPDLOG_LIBRARIES is C:\spdlog\lib\spdlogd.lib
# can work
target_link_libraries(test_example PRIVATE spdlog::spdlog)

# can't work => no such spdlog/spdlog.h
target_link_libraries(test_example PRIVATE ${SPDLOG_LIBRARIES})

```

```auto
#include "spdlog/spdlog.h"

int main(int, char *[])
{

    spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);

}

```

Why target\_link\_libraries(test\_example PRIVATE ${SPDLOG\_LIBRARIES})  
can not work?

---

<div class="post-metadata">

**Author:** ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)\
**Post date:** [September 10, 2024, 9:40am UTC](https://discourse.cmake.org/t/spdlog-libraries-vs-spdlog-spdlog/11632/2 "2024-09-10T09:40:42Z")

</div>

From what I see here, you linked directly to the library binaries (_`${SPDLOG_LIBRARIES}`_), not to its CMake target, so now you are missing include paths to the library headers. And if you linked to the target instead (_if you have a CMake config for it, that is_), most likely headers paths would’ve been set too (_but that of course depends on how this library’s maintainers composed its config_).

That `spdlog::spdlog` looks like a proper target, but nothing in your code fragment indicates where did it come from.

---

<div class="post-metadata">

**Author:** ![Sea\_Sea](https://discourse.cmake.org/user_avatar/discourse.cmake.org/sea_sea/32/4025_2.png) [@Sea\_Sea](https://discourse.cmake.org/u/Sea_Sea)\
**Post date:** [September 11, 2024, 12:44am UTC](https://discourse.cmake.org/t/spdlog-libraries-vs-spdlog-spdlog/11632/3 "2024-09-11T00:44:55Z")

</div>

A1:  
I don’t know the spdlog where did it come from too.  
I just download the [GitHub - gabime/spdlog: Fast C++ logging library.](https://github.com/gabime/spdlog) and install it.  
And set

```auto
find_package(SPDLOG REQUIRED)

```

and then I can use `spdlog::spdlog` that I don’t know how to generate it.

```auto
target_link_libraries(test_example PRIVATE spdlog::spdlog)

```

A2:  
Are you saying that the two pieces of code are the same?

```auto
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( SPDLOG REQUIRED )
include_directories( ${SPDLOG _INCLUDE_DIRS} )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage ${SPDLOG _LIBS} )

```

```auto
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( SPDLOG REQUIRED )
add_executable( DisplayImage DisplayImage.cpp )
target_link_libraries( DisplayImage spdlog::spdlog )

```

conclusion

```auto
include_directories( ${SPDLOG _INCLUDE_DIRS} )
target_link_libraries( DisplayImage ${SPDLOG _LIBS} )

# they are the same thing

target_link_libraries( DisplayImage spdlog::spdlog )

```

---

<div class="post-metadata">

**Author:** ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)\
**Post date:** [September 11, 2024, 6:53am UTC](https://discourse.cmake.org/t/spdlog-libraries-vs-spdlog-spdlog/11632/4 "2024-09-11T06:53:51Z")

</div>

They are not the same. CMake targets (like `spdlog::spdlog`) may carry more information, than just the include dirs, and what to link (linking flags, defines,…).  
Generally, if a target is available, you should link to it instead of playing with the variables. That’s the modern way.
