Summary
The following scenario is given:
- A C++ application is built either via Visual Studio 15 (2017) directly, or by using a script which in turn calls
cmake
directly. - We ran into trouble with the linker which was curious, since
cmake -G "Visual Studio 15 Win64"
is specified - Further inspection of the
CMakeCache.txt
has shown that the 32Bit linker is still used first for some reason:CMAKE_LINKER:FILEPATH=D:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/bin/Hostx86/x64/link.exe
(note theHostsx86
part. This is where aHostsx64
should be) - Additionally there is an unrelated
link.exe
which is provided by a Git installation (OS is Win10). This executable is selected from path apparently, when the 32Bit VSlink.exe
fails - The build process is successful when building from Visual Studio
So essentially what is observed is:
Visual Studio seems to use the 32Bit linker during the compilation process, despite cmake -G "Visual Studio 15 Win64"
being set when generating the project files. Then the 32Bit linker runs out of heap space and so the process reattempted with the usage of the 64Bit linker. However to find said linker the system path is checked and the link.exe
supplied by the Git installation is found first. At this point this linker is supplied with the source directory and parameters, but as it is a different application the build process then fails.
So far there is only speculation on my end as to why Visual Studio is able to compile and link successfully. Current guess is that Visual Studio checks some default locations before checking path and so the correct 64Bit link.exe
is found. This in turn allows the build and link process to finish successfully.
Attempted solutions
So I checked some ways to resolve this issue:
- Checked the
CMakeCache.txt
, the used linker is set there and it is the 32Bit version:CMAKE_LINKER:FILEPATH=D:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/bin/Hostx86/x64/link.exe
. Changing this before attempting compilation and linkage works. - Checked the environment variables, then inserted the proper
link.exe
path (i.e.D:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/bin/Hostx64/x64/link.exe
) into thePath
, so that it is found before the one supplied by the Git installation is found. This works. - Attempted to generate project files via CMake using
cmake -G "Visual Studio 15" -A x64 $src -B "build64" -T host=x64
. This does not work.
The problem with the solutions that work is, that they both require an explicit path to correct linker to be set in order to be able to compile via script. In addition the CMakeCache.txt
is generated during the build procedure, so setting it half-way through means the build process as a whole could not be executed.
Question
Is it at all possible to to configure CMake prior to executing the build pipeline via cmake
call, so that the 64Bit linker at the location D:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/bin/Hostx86/x64/link.exe
is used without explicitely setting this path somewhere (e.g. via CMake parameter during the cmake -G
call)?
Otherwise our contributors have to apply individualized solutions and set these paths individually on their systems. I am trying to find a solution where our script, which calls cmake -G
as well as the cmake
-build call after that is already configured so that the 64Bit linker is used from the get go and the 32Bit linker is omitted.
Another related option is likely a CMake toolchain file: CMake: specifying build toolchain
However this still requires setting a path manually. The 32Bit linker is found automatically though, is there no way to set the 64Bit linker automatically without providing an explicit path?
Thank you in advance, any input is welcome.