# CMAKE\_C\_LINK\_EXECUTABLE not considered for MINGW32

**URL:** <https://discourse.cmake.org/t/cmake-c-link-executable-not-considered-for-mingw32/254>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [November 25, 2019, 10:43am UTC](https://discourse.cmake.org/t/cmake-c-link-executable-not-considered-for-mingw32/254 "2019-11-25T10:43:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpoisel](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rpoisel/32/190_2.png) [@rpoisel](https://discourse.cmake.org/u/rpoisel)\
**Post date:** [November 25, 2019, 10:43am UTC](https://discourse.cmake.org/t/cmake-c-link-executable-not-considered-for-mingw32/254/1 "2019-11-25T10:43:46Z")

</div>

Hi,

I am trying to specify the `CMAKE_C_LINK_EXECUTABLE` and the `CMAKE_CXX_LINK_EXECUTABLE` variables in one of my toolchain files targetting MINGW32.

Any value specified for these two variables gets overwritten and therefore not considered at some point in the CMake config phase. It is even not considered when determining if my toolchain works.

I suspected that the problem resides somewhere in the `share` directory of my CMake installation (Version 3.15), but none of my search results for the two aforementioned variables looks as if the values would be overwritten there. In all cases they concern other toolchains than the ones for Windows/MINGW32 builds.

Thanks for your help!  
Rainer

---

<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:** [November 25, 2019, 7:22pm UTC](https://discourse.cmake.org/t/cmake-c-link-executable-not-considered-for-mingw32/254/2 "2019-11-25T19:22:55Z")

</div>

These variables are set by `Compiler/<id>-<lang>.cmake` and `Platform/<os>-<id>-<lang>.cmake` modules, where `<id>` is the compiler id CMake detects. For example, it is set for MinGW tools (GNU on Windows) in the builtin [Modules/Platform/Windows-GNU.cmake](https://gitlab.kitware.com/cmake/cmake/blob/v3.15.5/Modules/Platform/Windows-GNU.cmake#L110) that comes with CMake.

If you’re creating a new platform (e.g. with `CMAKE_SYSTEM_NAME` set to “MyPlatform”) then you should create a `MyPlatform-GNU-{C,CXX}.cmake` module in your project and add the root location to `CMAKE_MODULE_PATH` in the toolchain file.

Why do you want to override `CMAKE_{C,CXX}_LINK_EXECUTABLE`?

---

<div class="post-metadata">

**Author:** ![rpoisel](https://discourse.cmake.org/user_avatar/discourse.cmake.org/rpoisel/32/190_2.png) [@rpoisel](https://discourse.cmake.org/u/rpoisel)\
**Post date:** [November 26, 2019, 7:57am UTC](https://discourse.cmake.org/t/cmake-c-link-executable-not-considered-for-mingw32/254/3 "2019-11-26T07:57:27Z")

</div>

Hi Brad,

thanks a lot for your quick and helpful response! Looking into the `Windows-GNU.cmake` file revealed that the value of `CMAKE_${lang}_LINK_EXECUTABLE` is changed there. I was just searching for `CMAKE_C_LINK_EXECUTABLE`, that’s the reason I did not find it.

For us the solution seems to be to define our own platform that is copied from the Windows platform.

The reason we need to modify `CMAKE_C_LINK_EXECUTABLE` is that we want to run a coverage (CTC++) tool on our source base. In order to get that running, one needs to place it in front of the actual compiler/linker invocation, e. g.

```
ctc -i -m gcc.exe -c -o file.obj file.c
ctc gcc.exe -o file.exe file.obj

```

In case there is a better approach to this problem, please just let me know!

Best regards and thanks again,  
Rainer

---

<div class="post-metadata">

**Author:** ![erk](https://discourse.cmake.org/user_avatar/discourse.cmake.org/erk/32/114_2.png) [@erk](https://discourse.cmake.org/u/erk)\
**Post date:** [November 26, 2019, 8:22am UTC](https://discourse.cmake.org/t/cmake-c-link-executable-not-considered-for-mingw32/254/4 "2019-11-26T08:22:29Z")

</div>

Did you have a look at : `<LANG>_COMPILER_LAUNCHER` variable:

[https://cmake.org/cmake/help/v3.13/prop\_tgt/LANG\_COMPILER\_LAUNCHER.html#prop\_tgt:\<LANG\>\_COMPILER\_LAUNCHER](https://cmake.org/cmake/help/v3.13/prop_tgt/LANG_COMPILER_LAUNCHER.html#prop_tgt:%3CLANG%3E_COMPILER_LAUNCHER)

it can be used for your purpose I think.  
I use it for ccache but I guess your use case is similar.
