# Help with using Release/Debug for external dependency (Visual Studio CMAKE)

**URL:** https://discourse.cmake.org/t/help-with-using-release-debug-for-external-dependency-visual-studio-cmake/6689
**Category:** Code
**Tags:** os:windows
**Created:** [October 18, 2022, 12:46pm UTC](https://discourse.cmake.org/t/help-with-using-release-debug-for-external-dependency-visual-studio-cmake/6689 "2022-10-18T12:46:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JaybeeAB](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/bb73d2/32.png) [@JaybeeAB](https://discourse.cmake.org/u/JaybeeAB)
#### Post date: [October 18, 2022, 12:46pm UTC](https://discourse.cmake.org/t/help-with-using-release-debug-for-external-dependency-visual-studio-cmake/6689/1 "2022-10-18T12:46:10Z")

</div>

Hi there,

Apologies up front, I’m still learning CMake and using Visual Studio probably isn’t helping learn the basics (using it as its so good at debugging code).

I have a CMake project in Visual Studio and I’m linking to spdlog (performance logger). I checked out spdlog and used CMake-GUI to generate the make files. Then opened the VS solution files to build/install. Worth noting that even though CMake-GUI had CMAKE\_BUILD\_TYPE set to Release, that when I opened the generated files in VS, it was defaulting to debug. So I built as Debug (which also installed a cmake folder of cmake files and a pkgconfig folder), toggled it to Release and rebuilt (that built only the release lib file, but didn’t install the cmake/pkgconfig folder oddly and it built it into the src folder of spdlog not the installation folder).

I dropped the release build into the installation folder created by the debug build.

In my project CMakeLists.txt, I have

```auto
set(spdlog_DIR "C:/Work/Libs/spdlog/lib/cmake/spdlog")  
find_package(spdlog REQUIRED)

target_link_libraries(my-project PRIVATE spdlog::spdlog)

```

I also tried this as a test

```auto
target_link_libraries(my-project PRIVATE optimized spdlog::spdlog) 

```

but that seemed to do nothing.

I can build my project and use spdlog fine if my project (via VS UI) is in x64-Debug, but when I switch to x64-Release, I get linker errors and I can see it’s trying to link to spdlogd.lib (debug) not the spdlog.lib (release). Linker errors are  
`error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in my-project.cpp.obj`

I would have expected VS to pass the appropriate flags to CMake (or Ninja it seems - this bit confuses me) to link to the spdlog build type matching my project build type.

My spdlog installation folder is as so (as mentioned, I manually added the spdlog.lib into it, because the Release build only built the lib file - and in the src directory not the installation directory).

```auto
│ spdlog.lib
│ spdlogd.lib
│
├───cmake
│ └───spdlog
│ spdlogConfig.cmake
│ spdlogConfigTargets-debug.cmake
│ spdlogConfigTargets.cmake
│ spdlogConfigVersion.cmake
│
└───pkgconfig
        spdlog.pc

```

I could ask in an spdlog forum, but thought I’d try here first in case I’m doing something daft.  
Any assistance greatly appreciated.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [October 18, 2022, 1:28pm UTC](https://discourse.cmake.org/t/help-with-using-release-debug-for-external-dependency-visual-studio-cmake/6689/2 "2022-10-18T13:28:58Z")

</div>

> [@JaybeeAB](#):
>
> I dropped the release build into the installation folder created by the debug build.

Did you also drop the `lib/cmake` files the release install made into the same install tree? You should just be able to install both the release and debug configurations of `spdlog` to the same directory.

---

<div class="post-metadata">

### Author: ![JaybeeAB](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/bb73d2/32.png) [@JaybeeAB](https://discourse.cmake.org/u/JaybeeAB)
#### Post date: [October 18, 2022, 10:29pm UTC](https://discourse.cmake.org/t/help-with-using-release-debug-for-external-dependency-visual-studio-cmake/6689/3 "2022-10-18T22:29:53Z")

</div>

So… embarrassing. But yes, when I dropped in the spdlogConfigTargets-release.cmake file as well, it worked.

Side question, do you know if it’s possible to add a CMake-Gui parameter to change the output name? I’m also using pugixml and regardless of if it’s a Release or Debug, the output .lib name is the same (whereas spdlog suffixes a ‘d’ for the debug). I have renamed it manually and updated the cmake output debug file with the new filename, but wondered if there is a better way?

Thank you again.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [October 19, 2022, 11:36am UTC](https://discourse.cmake.org/t/help-with-using-release-debug-for-external-dependency-visual-studio-cmake/6689/4 "2022-10-19T11:36:52Z")

</div>

Assuming it’s not overridden internally, the `CMAKE_DEBUG_POSTFIX` variable will initialize the `DEBUG_POSTFIX` property.
