# custom linker tool using 3.29 LINKER\_TYPE

**URL:** https://discourse.cmake.org/t/custom-linker-tool-using-3-29-linker-type/13075
**Category:** Usage
**Tags:** os:linux, comp:gcc
**Created:** [November 27, 2024, 12:46pm UTC](https://discourse.cmake.org/t/custom-linker-tool-using-3-29-linker-type/13075 "2024-11-27T12:46:01Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![FloneStar](https://discourse.cmake.org/user_avatar/discourse.cmake.org/flonestar/32/5157_2.png) [@FloneStar](https://discourse.cmake.org/u/FloneStar)
#### Post date: [November 27, 2024, 12:46pm UTC](https://discourse.cmake.org/t/custom-linker-tool-using-3-29-linker-type/13075/1 "2024-11-27T12:46:01Z")

</div>

in our project we have the need to run a custom linker tool. This custom linker tool is supposed to be used for only some targets (some shared libs will be linked the normal way), not all. I have successfully registered the custom linker via setting CMAKE\_CXX\_USING\_LINKER\_customlinker and I also were able to set the LINKER\_TYPE property on the target. How can I tell CMake that only for this custom linker, CMAKE\_CXX\_USING\_LINKER\_MODE is supposed to be TOOL instead of FLAGS? There are no `CMAKE_<lang>_USING_LINKER_MODE_<custom linker>` properties, right?

---

<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: [November 27, 2024, 1:49pm UTC](https://discourse.cmake.org/t/custom-linker-tool-using-3-29-linker-type/13075/2 "2024-11-27T13:49:38Z")

</div>

For now, you cannot specify MODE per target because using the compiler as driver or directly the linker for the link step is defined using some global variables (like CMAKE\_\_CREATE\_SHARED\_LIBRARY, etc…).

The idea regarding `LINKER_TYPE` is that the compiler is aware of the linker and so, is able to manage softly the selection of the specified linker.

The case of a linker which cannot be used in coordination with the compiler is not supported.

In your case, may be the [\<LANG\>\_LINKER\_LAUNCHER](https://cmake.org/cmake/help/latest/prop_tgt/LANG_LINKER_LAUNCHER.html#prop_tgt:%3ECLANG%3E_LINKER_LAUNCHER) target property is more adequate to your needs.

---

<div class="post-metadata">

### Author: ![FloneStar](https://discourse.cmake.org/user_avatar/discourse.cmake.org/flonestar/32/5157_2.png) [@FloneStar](https://discourse.cmake.org/u/FloneStar)
#### Post date: [November 27, 2024, 1:54pm UTC](https://discourse.cmake.org/t/custom-linker-tool-using-3-29-linker-type/13075/3 "2024-11-27T13:54:57Z")

</div>

ah, thank you Marc. I gave it a try and yes, now I get my tool invoked. What is just now missing is the ability to pass additional tool options before the line that CMake passes into the linker wrapper. Can I do this without writing my own tool wrapper script? I would need a call to `myTool -prefixoption /path/to/g++ (etc)` instead of `myTool /path/to/g++ (etc)`

---

<div class="post-metadata">

### Author: ![FloneStar](https://discourse.cmake.org/user_avatar/discourse.cmake.org/flonestar/32/5157_2.png) [@FloneStar](https://discourse.cmake.org/u/FloneStar)
#### Post date: [November 27, 2024, 1:57pm UTC](https://discourse.cmake.org/t/custom-linker-tool-using-3-29-linker-type/13075/4 "2024-11-27T13:57:13Z")

</div>

in fact, best would be if I could stitch the whole command line manually together

---

<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: [November 27, 2024, 2:01pm UTC](https://discourse.cmake.org/t/custom-linker-tool-using-3-29-linker-type/13075/5 "2024-11-27T14:01:15Z")

</div>

`<LANG>_LINKER_LAUNCHER` is a semicolon separated list, so I think you can have:

```cmake
set_property(TARGET mytarget PROPERTY CXX_LINKER_LAUNCHER myTool -prefixoption)

```

---

<div class="post-metadata">

### Author: ![FloneStar](https://discourse.cmake.org/user_avatar/discourse.cmake.org/flonestar/32/5157_2.png) [@FloneStar](https://discourse.cmake.org/u/FloneStar)
#### Post date: [November 27, 2024, 2:04pm UTC](https://discourse.cmake.org/t/custom-linker-tool-using-3-29-linker-type/13075/6 "2024-11-27T14:04:25Z")

</div>

wow, thank you Marc, you are my hero!
