# Specifying linker by path is broken!

**URL:** https://discourse.cmake.org/t/specifying-linker-by-path-is-broken/13441
**Category:** Usage
**Tags:** os:linux, comp:clang
**Created:** [January 21, 2025, 9:17am UTC](https://discourse.cmake.org/t/specifying-linker-by-path-is-broken/13441 "2025-01-21T09:17:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Time0o](https://discourse.cmake.org/user_avatar/discourse.cmake.org/time0o/32/5295_2.png) [@Time0o](https://discourse.cmake.org/u/Time0o)
#### Post date: [January 21, 2025, 9:17am UTC](https://discourse.cmake.org/t/specifying-linker-by-path-is-broken/13441/1 "2025-01-21T09:17:16Z")

</div>

According to the [documentation](https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_USING_LINKER_TYPE.html) the following should be possible:

```auto
cmake -B build \
        -DCMAKE_C_COMPILER=/llvm-project/llvm/build/projects/bin/clang \
        -DCMAKE_CXX_COMPILER=/llvm-project/llvm/build/projects/bin/clang++ \
        -DCMAKE_LINKER_TYPE=LLD \
        -DCMAKE_CXX_USING_LINKER_LLD=/llvm-project/llvm/build/projects/bin/lld \
        -DCMAKE_CXX_USING_LINKER_MODE=TOOL

```

But this results in linking to be performed via the `clang++` frontend instead of the specified `lld`. Why is this documented if it plainly does not work at all? Or am I misunderstanding the docs?

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [January 21, 2025, 10:46am UTC](https://discourse.cmake.org/t/specifying-linker-by-path-is-broken/13441/2 "2025-01-21T10:46:41Z")

</div>

You effectively misunderstood how linker specification works.

It is possible to specify an alternate tool only on environments relying already directly on the linker tool for the link step: this is mainly the `Windows` platform with the `MSVC` compiler (or alternate compilers simulating this compiler). For other environments, the link step is done using the compiler as driver: this behavior cannot be changed.

Maybe some clarification is needed about these variables.

---

<div class="post-metadata">

### Author: ![Time0o](https://discourse.cmake.org/user_avatar/discourse.cmake.org/time0o/32/5295_2.png) [@Time0o](https://discourse.cmake.org/u/Time0o)
#### Post date: [January 21, 2025, 11:27am UTC](https://discourse.cmake.org/t/specifying-linker-by-path-is-broken/13441/3 "2025-01-21T11:27:47Z")

</div>

It’s not impossible to change this behavior, is it? There is `CMAKE_CXX_LINK_*` which lets you replace the compiler as a driver, I thought this was a new way to do just that but looking at the docs again they don’t actually imply that. And I don’t quite understand the purpose of `CMAKE_*_USING_LINKER_MODE` in that case since this seems to be “predetermined” by the compiler in use (i.e. TOOL for MSVS and FLAG for Clang/GCC).

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [January 21, 2025, 12:49pm UTC](https://discourse.cmake.org/t/specifying-linker-by-path-is-broken/13441/4 "2025-01-21T12:49:07Z")

</div>

It is not possible to change the behavior of how the link step is done (compiler as driver or linker).

And, effectively, the `CMAKE_*_USING_LINKER_MODE` variable is a bit curious but was there by the lack of the correct information. Now, `CMake` provides this information through the `CMAKE_<LANG>_LINK_MODE` variable, so this variable will be suppressed in some CMake future release.

---

<div class="post-metadata">

### Author: ![Time0o](https://discourse.cmake.org/user_avatar/discourse.cmake.org/time0o/32/5295_2.png) [@Time0o](https://discourse.cmake.org/u/Time0o)
#### Post date: [January 21, 2025, 12:53pm UTC](https://discourse.cmake.org/t/specifying-linker-by-path-is-broken/13441/5 "2025-01-21T12:53:36Z")

</div>

Okay, that makes sense then, thank you
