Description
Hi,
We are trying to build a binary on Windows using a specific set of Visual Studio (installed under C:\Users\ydfb4q\BDM-2130\16.9.31910.168
) and Windows libraries (C:\Users\ydfb4q\BDM-2130\10.0.19041.0
).
No VS installed
This is working as expected with -winsdkdir
and -vctoolsdir
when there is no Visual Studio installed on the system:
.\clang.exe -fuse-ld=lld-link.exe C:\Users\ydfb4q\BDM-2130\hello.cpp -Wl,-vctoolsdir:C:\Users\ydfb4q\BDM-2130\16.9.31910.168\Professional\VC\Tools\MSVC\14.28.29910\ -Wl,-winsdkdir:C:\Users\ydfb4q\BDM-2130\10.0.19041.0\ -o C:\Users\ydfb4q\BDM-2130\hello.exe -L C:\Users\ydfb4q\BDM-2130\10.0.19041.0\lib\um\x64\ -Wl,-verbose -isystem C:\Users\ydfb4q\BDM-2130\16.9.31910.168\Professional\VC\Tools\MSVC\14.28.29910\include -isystem C:\Users\ydfb4q\BDM-2130\10.0.19041.0\include\ucrt
link_no_vs.txt indicates the correct libraries being used:
lld-link: Reading C:\Users\ydfb4q\BDM-2130\10.0.19041.0\lib\um\x64\kernel32.lib
lld-link: Reading C:\Users\ydfb4q\BDM-2130\16.9.31910.168\Professional\VC\Tools\MSVC\14.28.29910\lib\x64\libvcruntime.lib
lld-link: Reading C:\Users\ydfb4q\BDM-2130\10.0.19041.0\Lib\ucrt\x64\libucrt.lib
VS installed
After installing Visual Studio on the system, we would still like ignore its installation when linking our binary. However, the same command line no leads to link_with_vs_installed.txt, which shows that system libraries are pulled in:
lld-link: Reading C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x64\kernel32.lib
lld-link: Reading c:\apps\MVS174\VC\Tools\MSVC\14.34.31933\lib\x64\libvcruntime.lib
lld-link: Reading C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\ucrt\x64\libucrt.lib
Setting the VCINSTALLDIR
environment variable
set VCINSTALLDIR=C:\Users\ydfb4q\BDM-2130\16.9.31910.168
leads to correctly picking up the Visual Studio libraries (but still the system Windows libraries, obviously): link_with_vs_installed-vcinstalldir.txt
lld-link: Reading C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x64\kernel32.lib
lld-link: Reading C:\Users\ydfb4q\BDM-2130\16.9.31910.168\Professional\VC\Tools\MSVC\14.28.29910\lib\x64\libvcruntime.lib
lld-link: Reading C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\ucrt\x64\libucrt.lib
Setting the WindowsSdkDir
environment variable
set WindowsSdkDir=C:\Users\ydfb4q\BDM-2130\10.0.19041.0
has no effect, it is still linking against the system Windows libs: link_with_vs_installed-vcinstalldir-windowssdkdir.txt
lld-link: Reading C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x64\kernel32.lib
lld-link: Reading C:\Users\ydfb4q\BDM-2130\16.9.31910.168\Professional\VC\Tools\MSVC\14.28.29910\lib\x64\libvcruntime.lib
lld-link: Reading C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\ucrt\x64\libucrt.lib
Workaround
The only way we could find to get the desired behavior is to specify absolute paths to the Windows system libraries, adding
-lC:\Users\ydfb4q\BDM-2130\10.0.19041.0\lib\um\x64\kernel32.lib -lC:\Users\ydfb4q\BDM-2130\10.0.19041.0\lib\um\x64\uuid.lib -lC:\Users\ydfb4q\BDM-2130\10.0.19041.0\lib\ucrt\x64\libucrt.lib
to the command line: link_with_vs_installed-vcinstalldir-windowssdkdir-explicitpath.txt
lld-link: Reading C:\Users\ydfb4q\BDM-2130\10.0.19041.0\lib\um\x64\kernel32.lib
lld-link: Reading C:\Users\ydfb4q\BDM-2130\10.0.19041.0\lib\um\x64\uuid.lib
lld-link: Reading C:\Users\ydfb4q\BDM-2130\10.0.19041.0\lib\ucrt\x64\libucrt.lib
lld-link: Reading C:\Users\ydfb4q\BDM-2130\16.9.31910.168\Professional\VC\Tools\MSVC\14.28.29910\lib\x64\libcpmt.lib
While that works, it is not very robust, because we have to specify all libraries explicitly. If we were to change our source code to require more Windows libraries, there is always the risk of unintendedly pulling in system libraries.
Can we somehow get -winsdkdir
to take precedence over any system-installed libraries? The same question applies to -vctoolsdir
. Ideally, it would pick up only the libraries under the specified location without having to set VCTOOLSDIR
additionally.