# Correct way to set required linker-only arguments in toolchain

**URL:** https://discourse.cmake.org/t/correct-way-to-set-required-linker-only-arguments-in-toolchain/15647
**Category:** Code
**Created:** [May 9, 2026, 2:52am UTC](https://discourse.cmake.org/t/correct-way-to-set-required-linker-only-arguments-in-toolchain/15647 "2026-05-09T02:52:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![DanShaders](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/85f322/32.png) [@DanShaders](https://discourse.cmake.org/u/DanShaders)
#### Post date: [May 9, 2026, 2:52am UTC](https://discourse.cmake.org/t/correct-way-to-set-required-linker-only-arguments-in-toolchain/15647/1 "2026-05-09T02:52:34Z")

</div>

I have a toolchain file which needs to set `-rtlib=compiler-rt` as a “required” linker flag (i. e. without it, the toolchain will either not work or silently generate broken code). As far as I can tell, I have a couple options:

- Set `CMAKE_*_LINKER_FLAGS_INIT`. However, it is overridable from the cmdline and there is no guarantee that the user won’t forget about compiler-rt.
- Do `set(CMAKE_C_COMPILER clang -rtlib=compiler-rt -Qunused-arguments)` which is not amazing since `-rtlib=compiler-rt` is now passed during compilation as well.
- Do some weird dance with setting something like `MY_PROJECT_REQUIRED_LINKER_FLAGS` in toolchain and then prepending to `CMAKE_*_LINKER_FLAGS` at the top of project’s CMakeLists.txt guarded by top-level check.
- Use `CMAKE_USER_MAKE_RULES_OVERRIDE_{C,CXX}` and try to guess what `CMAKE_CXX_CREATE_SHARED_LIBRARY` & co. are being set to in the version of CMake that happens to be installed on the user machine.

and neither of them is particularly nice. So, what is the current best practice?

---

<div class="post-metadata">

### Author: ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)
#### Post date: [May 9, 2026, 5:39pm UTC](https://discourse.cmake.org/t/correct-way-to-set-required-linker-only-arguments-in-toolchain/15647/2 "2026-05-09T17:39:21Z")

</div>

Why not [add\_link\_options](https://cmake.org/cmake/help/latest/command/add_link_options.html)?

---

<div class="post-metadata">

### Author: ![DanShaders](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/85f322/32.png) [@DanShaders](https://discourse.cmake.org/u/DanShaders)
#### Post date: [May 10, 2026, 5:55pm UTC](https://discourse.cmake.org/t/correct-way-to-set-required-linker-only-arguments-in-toolchain/15647/3 "2026-05-10T17:55:11Z")

</div>

Oh, wow, thanks! It never occurred to me that `add_{compile,link}_options` work inside a toolchain file.
