Issue: TCC compiles, but fails to link, with Error: Unable to execute command 'tlink.exe'
Cause: This happens when invoking TCC as a compiler+linker, without the -c
flag. To locate TLINK, TCC needlessly copies the PATH
environment variable into a statically allocated 128-byte buffer. It then constructs absolute tlink.exe
filenames for each of the semicolon- or \0
-terminated paths, writing these into a buffer that immediately follows the 128-byte PATH
buffer in memory. The search is finished as soon as TCC finds an existing file, which gives precedence to earlier paths in the PATH
. If the search didn't complete until a potential "final" path that runs past the 128 bytes, the final attempted filename will consist of the part that still managed to fit into the buffer, followed by the previously attempted path.
Workaround: Make sure that the BIN\
path to Turbo C++ is fully contained within the first 127 bytes of the PATH
inside your DOS system.
(The 128th byte must either be a separating ;
or the terminating \0
of the PATH
string.)
(Initially discovered by the ReC98 project on 2021-08-02. Nowadays, its build process calls TLINK directly, replicating TCC's link response file generation in the build script.)