# How do I specify different binaries to link against for Visual Studio debug and release, but be able to select either

**URL:** https://discourse.cmake.org/t/how-do-i-specify-different-binaries-to-link-against-for-visual-studio-debug-and-release-but-be-able-to-select-either/2026
**Category:** Usage
**Created:** [October 19, 2020, 9:34pm UTC](https://discourse.cmake.org/t/how-do-i-specify-different-binaries-to-link-against-for-visual-studio-debug-and-release-but-be-able-to-select-either/2026 "2020-10-19T21:34:43Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![imlost](https://discourse.cmake.org/user_avatar/discourse.cmake.org/imlost/32/676_2.png) [@imlost](https://discourse.cmake.org/u/imlost)
#### Post date: [October 19, 2020, 9:34pm UTC](https://discourse.cmake.org/t/how-do-i-specify-different-binaries-to-link-against-for-visual-studio-debug-and-release-but-be-able-to-select-either/2026/1 "2020-10-19T21:34:43Z")

</div>

How do I specify in CMAKE that binary file A is for debug and B is for release when linking, but in such a way I can still toggle between the two in VS and not have to do cmake … each time I need to switch between the two.

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [October 20, 2020, 4:56am UTC](https://discourse.cmake.org/t/how-do-i-specify-different-binaries-to-link-against-for-visual-studio-debug-and-release-but-be-able-to-select-either/2026/2 "2020-10-20T04:56:11Z")

</div>

What do you mean by binaries?

Do you mean targets or system libraries?

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [October 20, 2020, 7:31am UTC](https://discourse.cmake.org/t/how-do-i-specify-different-binaries-to-link-against-for-visual-studio-debug-and-release-but-be-able-to-select-either/2026/3 "2020-10-20T07:31:25Z")

</div>

```
target_link_libraries(consumer debug A optimized B)

```

See [relevant docs](https://cmake.org/cmake/help/latest/command/target_link_libraries.html?highlight=optimized).

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [October 20, 2020, 7:36am UTC](https://discourse.cmake.org/t/how-do-i-specify-different-binaries-to-link-against-for-visual-studio-debug-and-release-but-be-able-to-select-either/2026/4 "2020-10-20T07:36:35Z")

</div>

This is the same thing with generator expressions and using PRIVATE to hide the dependencies.

```auto
target_link_libraries(foo PRIVATE
    $<$<CONFIG:Debug>:
        bar
    >

    $<$<CONFIG:Release>:
        yo
    >
)

```

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [October 20, 2020, 7:50am UTC](https://discourse.cmake.org/t/how-do-i-specify-different-binaries-to-link-against-for-visual-studio-debug-and-release-but-be-able-to-select-either/2026/5 "2020-10-20T07:50:39Z")

</div>

Are you sure the genex will survive the line breaks?

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [October 20, 2020, 7:52am UTC](https://discourse.cmake.org/t/how-do-i-specify-different-binaries-to-link-against-for-visual-studio-debug-and-release-but-be-able-to-select-either/2026/6 "2020-10-20T07:52:34Z")

</div>

I have similar code in my own project.

---

<div class="post-metadata">

### Author: ![imlost](https://discourse.cmake.org/user_avatar/discourse.cmake.org/imlost/32/676_2.png) [@imlost](https://discourse.cmake.org/u/imlost)
#### Post date: [October 20, 2020, 5:27pm UTC](https://discourse.cmake.org/t/how-do-i-specify-different-binaries-to-link-against-for-visual-studio-debug-and-release-but-be-able-to-select-either/2026/7 "2020-10-20T17:27:29Z")

</div>

😛 should have known it was just a parameter in target\_link\_libraries. Was thinking I had to put in a special logic block specifying it as for release. Thanks guys.

---

<div class="post-metadata">

### Author: ![anon45792294](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@anon45792294](https://discourse.cmake.org/u/anon45792294)
#### Post date: [October 21, 2020, 4:22pm UTC](https://discourse.cmake.org/t/how-do-i-specify-different-binaries-to-link-against-for-visual-studio-debug-and-release-but-be-able-to-select-either/2026/8 "2020-10-21T16:22:25Z")

</div>

No problem just make sure to mark the question as answered.
