Customizing linker and redirecting the STDIO to a file


I am using an ancient WindRiver diab compiler / linker. I managed to configure the toolchain so it properly finds the commands. My problem now is that the linker outputs the map file to the stdio, only. So, as simple as that, I thought adding a redirect to CMAKE_C_LINK_EXECUTABLE would solve the matter


This variant fails when running cmake during the toolchain check.

So I added it to the linker flags and reorder the assembly of the command line so the redirect is at the end. Not nice, but worth a try.


The result is the linker complaining that “>” was assumed to be an input file which could not be found. In verbose mode, I copied the command line displayed to the shell prompt and there it worked well.

Any idea how I can redirect output of certain build steps to target specific text file?


Have a look at the CMAKE_<LANG>_LINKER_LAUNCHER variable.


thanks for fast response.

Documentation to the variable is not very comprehensible so I could work with it. Is it similar to CMAKE_C_LINK_EXECUTABLE?

The part which confuses me is the fact that the resulting Makefile outputs a command line in verbose mode for which link fails. But when copy&paste this very line to the shell prompt, it works.

Any idea or further guidance where I can find more elaborated information about the variable you mentioned?


A little bit more details, maybe towards people being familiar with cmake under the hood and experts to UNIX IO:

Linking is done by link.txt. This file contains a Make rule for the executable. This file is not included by a parent Makefile but it is passed as a parameter to cmake from build.make. It looks like

some_ELF: CMakeFiles/some_ELF.dir/link.txt
@$(CMAKE_COMMAND) -E cmake_echo_color “–switch=$(COLOR)” --green --bold --progress-dir=CMakeFiles --progress-num=$(CMAKE_PROGRESS_22) “Linking C executable some_ELF”
$(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/some_ELF.dir/link.txt --verbose=$(VERBOSE)

This means, that any redirection is passed as a parameter to cmake, will cause confusions because redirection is a shell feature.

Has anyone an idea how to redirect stdout in a different manner than > file on command line? Or is that what you meant with the …_LAUNCHER variable?


You could make a wrapper shell script of your own the linker. This script can solve the problem internally.

1 Like

Note that when CMake runs the linker, it does so directly, not via a shell. Therefore, you can’t use any shell redirection symbols as part of the command line. I’d recommend you follow @hsattler’s suggestion of writing your own wrapper script that handles the redirection internally.

1 Like

Thanks, I now use

and it works.