# Why CMake doesn't provide variables to select the type of linking to GNU system libraries?

**URL:** https://discourse.cmake.org/t/why-cmake-doesnt-provide-variables-to-select-the-type-of-linking-to-gnu-system-libraries/11418
**Category:** Development
**Created:** [August 9, 2024, 8:50pm UTC](https://discourse.cmake.org/t/why-cmake-doesnt-provide-variables-to-select-the-type-of-linking-to-gnu-system-libraries/11418 "2024-08-09T20:50:30Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Daniel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/3ec8ea/32.png) [@Daniel](https://discourse.cmake.org/u/Daniel)
#### Post date: [August 9, 2024, 8:50pm UTC](https://discourse.cmake.org/t/why-cmake-doesnt-provide-variables-to-select-the-type-of-linking-to-gnu-system-libraries/11418/1 "2024-08-09T20:50:30Z")

</div>

Starting from version 3.15, we can explicitly set the type of linking to the MSVC runtime library by setting the value [CMAKE\_MSVC\_RUNTIME\_LIBRARY](https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html).

Next, in 3.24, the [CMAKE\_WATCOM\_RUNTIME\_LIBRARY](https://cmake.org/cmake/help/latest/variable/CMAKE_WATCOM_RUNTIME_LIBRARY.html) variable was introduced to provide a similar feature for Waston.

But unfortunately, we don’t have anything like this for libraries such as: libstdc++, libc++ and also C libraries.

In my opinion, CMake could have a variable whose value would pass the `-static-libgcc -static-libstdc++` flags to the compiler with GNU frontend with suitable environment (and don’t forget about `-shared-libgcc` -`shared-libstdc++` for TDM-GCC). I should add that it would be useful with MSYS2 and Windows.

**Q:** If this is not planned, what are the objective reasons for the absence of the described feature?  
This question seems obvious, but I have not found a similar discussion.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [August 12, 2024, 2:58pm UTC](https://discourse.cmake.org/t/why-cmake-doesnt-provide-variables-to-select-the-type-of-linking-to-gnu-system-libraries/11418/2 "2024-08-12T14:58:18Z")

</div>

See [CMake Issue 20851](https://gitlab.kitware.com/cmake/cmake/-/issues/20851) for discussion of an abstraction for C++ standard library selection.

Although CMake doesn’t provide an abstraction for this, one can specify `CXXFLAGS=-static-libgcc -static-libstdc++` in the environment to achieve the requested behavior.
