# Chaging order of options in the link command of a cross-compilation project via CMAKE\_CXX\_LINK\_EXECUTABLE

**URL:** https://discourse.cmake.org/t/chaging-order-of-options-in-the-link-command-of-a-cross-compilation-project-via-cmake-cxx-link-executable/1346
**Category:** Usage
**Tags:** comp:ti
**Created:** [June 8, 2020, 2:07pm UTC](https://discourse.cmake.org/t/chaging-order-of-options-in-the-link-command-of-a-cross-compilation-project-via-cmake-cxx-link-executable/1346 "2020-06-08T14:07:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jairo](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jairo/32/672_2.png) [@jairo](https://discourse.cmake.org/u/jairo)
#### Post date: [June 8, 2020, 2:07pm UTC](https://discourse.cmake.org/t/chaging-order-of-options-in-the-link-command-of-a-cross-compilation-project-via-cmake-cxx-link-executable/1346/1 "2020-06-08T14:07:58Z")

</div>

I have a CMake toolchain file to cross-compile to a TI C2000 (C28x) MCU. The compilation seems to go well except during the link process I receive a couple of warnings, the relevant warning says

```plaintext
warning: Option -o is an alias of linker option --output_file. The specified
   argument of off is also a valid argument for the compiler option --opt_level
   (-o). If the intent is to specify the optimization level, the option should
   be specified before the --run_linker(-z) option. As specified, the output
   file of the linker will be off

```

Specifically the part

> If the intent is to specify the optimization level, the option should be specified before the --run\_linker(-z) option. As specified, the output file of the linker will be off"

My understanding is that if I want to change where the linker flags are placed in the command I have to modify `CMAKE_CXX_LINKER_EXECUTABLE`/`CMAKE_C_LINKER_EXECUTABLE`, however setting this variable seems to have no effect. I’ve tried setting it on the command line, in the toolchain file and in the CMakeLists.txt.

The source code [here](https://github.com/Kitware/CMake/blob/v3.5.1/Modules/Compiler/TI-CXX.cmake) specifies this variable as:

```cmake
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> --run_linker --output_file=<TARGET> --map_file=<TARGET>.map <CMAKE_CXX_LINK_FLAGS> <LINK_LIBRARIES> <LINK_FLAGS> <OBJECTS>")

```

and I’d like to place `CMAKE_CXX_LINK_FLAGS` and `LINK_FLAGS` _before_ the `--run-linker` command as suggested in the warning.

Any idea how I can override this?

---

<div class="post-metadata">

### Author: ![jairo](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jairo/32/672_2.png) [@jairo](https://discourse.cmake.org/u/jairo)
#### Post date: [June 10, 2020, 8:17pm UTC](https://discourse.cmake.org/t/chaging-order-of-options-in-the-link-command-of-a-cross-compilation-project-via-cmake-cxx-link-executable/1346/2 "2020-06-10T20:17:15Z")

</div>

I found this conversation: [CMAKE\_C\_LINK\_EXECUTABLE not considered for MINGW32](https://discourse.cmake.org/t/cmake-c-link-executable-not-considered-for-mingw32/254)

Looks like their suggestion there is to make a custom platform ID where I can populate the `CMAKE_C_LINK_EXECUTABLE`/`CMAKE_CXX_LINK_EXECUTABLE` which ever way I want. This makes me wonder if this is a deficiency in the implementation of [`Modules/Compiler/TI-CXX.cmake`](https://github.com/Kitware/CMake/blob/v3.5.1/Modules/Compiler/TI-CXX.cmake). Should it be checking if it’s defined before it `set()`'s the variable? e.g.

```cmake
if(NOT DEFINED CMAKE_C_LINK_EXECUTABLE)
    set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> --run_linker --output_file=<TARGET> --map_file=<TARGET>.map <CMAKE_CXX_LINK_FLAGS> <LINK_LIBRARIES> <LINK_FLAGS> <OBJECTS>")
endif()
```

---

<div class="post-metadata">

### Author: ![jairo](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jairo/32/672_2.png) [@jairo](https://discourse.cmake.org/u/jairo)
#### Post date: [June 19, 2020, 1:48pm UTC](https://discourse.cmake.org/t/chaging-order-of-options-in-the-link-command-of-a-cross-compilation-project-via-cmake-cxx-link-executable/1346/3 "2020-06-19T13:48:40Z")

</div>

Solved! See here: [Modifying CMAKE\_\<LANG\>\_LINK\_EXECUTABLE in toolchain file](https://discourse.cmake.org/t/modifying-cmake-lang-link-executable-in-toolchain-file/1386/4)
