# Is there a CMAKE\_CXX\_COMPILER\_LAUNCHER but for the linker?

**URL:** <https://discourse.cmake.org/t/is-there-a-cmake-cxx-compiler-launcher-but-for-the-linker/2591>\
**Category:** Code\
**Created:** [January 20, 2021, 7:41pm UTC](https://discourse.cmake.org/t/is-there-a-cmake-cxx-compiler-launcher-but-for-the-linker/2591 "2021-01-20T19:41:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Rogers](https://discourse.cmake.org/user_avatar/discourse.cmake.org/matt_rogers/32/582_2.png) [@Matt\_Rogers](https://discourse.cmake.org/u/Matt_Rogers)\
**Post date:** [January 20, 2021, 7:41pm UTC](https://discourse.cmake.org/t/is-there-a-cmake-cxx-compiler-launcher-but-for-the-linker/2591/1 "2021-01-20T19:41:09Z")

</div>

I’m having some trouble finding this information, so sorry if I missed something in the documentation. But I have a project with a separate compiler and linker, and they both require certain environment variables to be set up beforehand, I managed to get around this for the compiler by using CMAKE\_CXX\_COMPILER\_LAUNCHER with a batch script that set the relevant variables before invoking the compiler, but I’m having trouble with figuring out how to do the same for the linker.

---

<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:** [January 20, 2021, 8:06pm UTC](https://discourse.cmake.org/t/is-there-a-cmake-cxx-compiler-launcher-but-for-the-linker/2591/2 "2021-01-20T20:06:46Z")

</div>

The compiler is usually used as the linker as well, though I don’t know if the link rule ends up using the configured launcher. @brad.king?

---

<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:** [January 20, 2021, 8:15pm UTC](https://discourse.cmake.org/t/is-there-a-cmake-cxx-compiler-launcher-but-for-the-linker/2591/3 "2021-01-20T20:15:52Z")

</div>

@Matt_Rogers see [CMake Issue 18351](https://gitlab.kitware.com/cmake/cmake/-/issues/18351) and discussion in [CMake Issue 18316](https://gitlab.kitware.com/cmake/cmake/-/issues/18316#note_451855).

@ben.boeckel I think the idea is that a different launcher should be used for the same compiler driver based on whether it is launching a compile step or a link step. `ccache` works for compiling, but some other tool could be used to wrap linking.

---

<div class="post-metadata">

**Author:** ![Matt\_Rogers](https://discourse.cmake.org/user_avatar/discourse.cmake.org/matt_rogers/32/582_2.png) [@Matt\_Rogers](https://discourse.cmake.org/u/Matt_Rogers)\
**Post date:** [January 20, 2021, 8:37pm UTC](https://discourse.cmake.org/t/is-there-a-cmake-cxx-compiler-launcher-but-for-the-linker/2591/4 "2021-01-20T20:37:52Z")

</div>

@ben.boeckel

I understand that this is usually true, but we have a bit of a weird setup where the linker and compiler that we use are different executables, and the CMAKE\_CXX\_COMPILER\_LAUNCHER is not invoked when doing the link step. So to clarify we have different executables specified for CMAKE\_CXX\_COMPILER and CXX\_LINKER.

Looking at the resulting build.ninja file the linker invocation is not invoked via the CMAKE\_CXX\_COMPILER\_LAUNCHER variable.

@brad.king Is there any active development in the direction of those issues or is that dead in the water right now?

---

<div class="post-metadata">

**Author:** ![ferdnyc](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ferdnyc/32/267_2.png) [@ferdnyc](https://discourse.cmake.org/u/ferdnyc)\
**Post date:** [January 20, 2021, 10:43pm UTC](https://discourse.cmake.org/t/is-there-a-cmake-cxx-compiler-launcher-but-for-the-linker/2591/5 "2021-01-20T22:43:44Z")

</div>

If you’re using `gcc` or `clang` (or other compatible compiler), you can set the linker _it_ uses with the `-fuse-ld=` argument. Just add that to `CMAKE_[C/CXX]_COMPILER_FLAGS` and CMake doesn’t have to worry about the linker executable details.

See [my stackoverflow answer](https://stackoverflow.com/a/64174822/200794) on exactly this topic.

---

<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:** [January 21, 2021, 2:31pm UTC](https://discourse.cmake.org/t/is-there-a-cmake-cxx-compiler-launcher-but-for-the-linker/2591/6 "2021-01-21T14:31:35Z")

</div>

> [@Matt\_Rogers](#):
>
> Is there any active development in the direction of those issues

No one upstream is working on it currently, but I’d be happy to review proposed changes in a merge request.

---

<div class="post-metadata">

**Author:** ![KUGA2](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kuga2/32/4968_2.png) [@KUGA2](https://discourse.cmake.org/u/KUGA2)\
**Post date:** [October 12, 2021, 11:10am UTC](https://discourse.cmake.org/t/is-there-a-cmake-cxx-compiler-launcher-but-for-the-linker/2591/7 "2021-10-12T11:10:10Z")

</div>

Note for Readers from search machines:

[CMAKE\_LANG\_LINKER\_LAUNCHER](https://cmake.org/cmake/help/latest/envvar/CMAKE_LANG_LINKER_LAUNCHER.html) and acording property was added in CMake 3.21
