CLion 2020.3 - Visual Studio Build Tools link error

Answered

I have recently encountered an issue where I get loads of errors when CMake does a basic compiler check.

The errors are as follows:

"C:\Program Files\JetBrains\CLion 2020.3.2\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_C_COMPILER=C:/Program Files/LLVM/bin/clang-cl.exe" "-DCMAKE_CXX_COMPILER=C:/Program Files/LLVM/bin/clang-cl.exe" -DCMAKE_C_FLAGS=-m64 -DCMAKE_CXX_FLAGS=-m64 -G "CodeBlocks - NMake Makefiles" D:\ASGE-Repositories\asgenetgame-team-11
-- The CXX compiler identification is Clang 11.0.0 with MSVC-like command-line
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang-cl.exe
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang-cl.exe - broken
CMake Error at C:/Program Files/JetBrains/CLion 2020.3.2/bin/cmake/win/share/cmake-3.17/Modules/CMakeTestCXXCompiler.cmake:53 (message):
The C++ compiler

"C:/Program Files/LLVM/bin/clang-cl.exe"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: D:/ASGE-Repositories/asgenetgame-team-11/cmake-build-debug/CMakeFiles/CMakeTmp

Run Build Command(s):nmake /nologo cmTC_8bbb0\fast && "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29333\bin\HostX64\x64\nmake.exe" -f CMakeFiles\cmTC_8bbb0.dir\build.make /nologo -L CMakeFiles\cmTC_8bbb0.dir\build
Building CXX object CMakeFiles/cmTC_8bbb0.dir/testCXXCompiler.cxx.obj
C:\PROGRA~1\LLVM\bin\clang-cl.exe @C:\Users\zackj\AppData\Local\Temp\nmFE32.tmp
Linking CXX executable cmTC_8bbb0.exe
"C:\Program Files\JetBrains\CLion 2020.3.2\bin\cmake\win\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_8bbb0.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\mt.exe --manifests -- C:\PROGRA~1\LLVM\bin\lld-link.exe /nologo @CMakeFiles\cmTC_8bbb0.dir\objects1.rsp @C:\Users\zackj\AppData\Local\Temp\nmFE62.tmp
LINK Pass 1: command "C:\PROGRA~1\LLVM\bin\lld-link.exe /nologo @CMakeFiles\cmTC_8bbb0.dir\objects1.rsp /out:cmTC_8bbb0.exe /implib:cmTC_8bbb0.lib /pdb:D:\ASGE-Repositories\asgenetgame-team-11\cmake-build-debug\CMakeFiles\CMakeTmp\cmTC_8bbb0.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_8bbb0.dir/intermediate.manifest CMakeFiles\cmTC_8bbb0.dir/manifest.res" failed (exit code 1) with the following output:
lld-link: error: could not open 'kernel32.lib': no such file or directory
lld-link: error: could not open 'user32.lib': no such file or directory
lld-link: error: could not open 'gdi32.lib': no such file or directory
lld-link: error: could not open 'winspool.lib': no such file or directory
lld-link: error: could not open 'shell32.lib': no such file or directory
lld-link: error: could not open 'ole32.lib': no such file or directory
lld-link: error: could not open 'oleaut32.lib': no such file or directory
lld-link: error: could not open 'uuid.lib': no such file or directory
lld-link: error: could not open 'comdlg32.lib': no such file or directory
lld-link: error: could not open 'advapi32.lib': no such file or directory
NMAKE : fatal error U1077: '"C:\Program Files\JetBrains\CLion 2020.3.2\bin\cmake\win\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29333\bin\HostX64\x64\nmake.exe"' : return code '0x2'
Stop.

 

I have tried reinstalling both CLion & Visual studio build tools, as well as installing different versions of both, but neither has done anything to change the error messages.

Below is my toolchain setup as well

 
0
4 comments

Hello!

Are you able to build this CMake project with this compiler outside CLion, for example, in Command Prompt?

0

I fell into a similar situation and was able to fix it by installing another Windows SDK in "Visual Studio Installer".

I just unselected the currently checked "Windows SDK 10" and selected the latest "Windows 11 SDK" and everything goes fine as before.

However, I don't know the reasons behind these. If my memory serves, I just updated Visual Studio via the Visual Studio Installer days before.

I also answered a question on Stack Overflow. https://stackoverflow.com/a/72714420/18472514 

See also Linker Tools Error LNK1104 - Microsoft Docs. https://docs.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk1104?view=msvc-170 

 

1

I met the same link error. The solution from Henry Wood worked for it as well.

In comparison, I selected another version of "Windows SDK 10", not the latest "Windows 11 SDK", and I immediately tried to compile in CLion 2022 1.3, even before the whole installation of the "Windows SDK 10" finished. The solution above still worked well and I successfully compiled.

Thanks a lot for the solution from Henry Wood, even though I am unable to understand the hidden mechanism.

0

😂 Well, I'd rather regard this as a Visual Studio installation bug instead of some "hidden mechanism". On my computer, the latest Visual Studio installation with C++ workload seems uncomplete, and I have to check another Windows SDK in the installer to fix the SDK installation. 

Besides, MSBuild also has a bug causing it to ignore the found Windows SDK, which fails in Visual Studio (non CMake projects, which use MSBuild as default) and other IDEs. So I'm using Ninja with CMake and it works fine.

By the way, the clang-cl toolset used to break with CLion (a `-m64` flag in generated CMakeCache.txt causes a failure which when linking with external libraries in vcpkg). I'm not sure whether this has been fixed or not, or maybe actually it's some feature?

Anyway, my recommendation is MSVC Clang + Ninja, which should work in most cases. 😂

0

Please sign in to leave a comment.