CLion EWDK MSVC Toolchain doesn't find kernel32.Lib

Answered

Morning,

I am currently moving my whole dev environment from VS2019 to CLion and can't get the Enterprise Windows Driver Kit (WDK) build environment working. After setting up the toolchain I get the following error message:

-- The C compiler identification is MSVC 19.28.29913.0
-- The CXX compiler identification is MSVC 19.28.29913.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: E:/Program Files/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: E:/Program Files/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - broken
CMake Error at C:/Program Files/JetBrains/CLion 2021.3.2/bin/cmake/win/share/cmake-3.21/Modules/CMakeTestCCompiler.cmake:69 (message):
  The C compiler

    "E:/Program Files/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: A:/Git/School/Driver/cmake-build-debug/CMakeFiles/CMakeTmp
    
    Run Build Command(s):C:/Program Files/JetBrains/CLion 2021.3.2/bin/ninja/win/ninja.exe cmTC_02d23 && [1/2] Building C object CMakeFiles\cmTC_02d23.dir\testCCompiler.c.obj
    [2/2] Linking C executable cmTC_02d23.exe
    FAILED: cmTC_02d23.exe 
    cmd.exe /C "cd . && "C:\Program Files\JetBrains\CLion 2021.3.2\bin\cmake\win\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_02d23.dir --rc="E:\PROG#OLC\WIND#B-J\10\bin\1002#1AM.0\x86\rc.exe" --mt="E:\PROG#OLC\WIND#B-J\10\bin\1002#1AM.0\x86\mt.exe" --manifests  -- "E:\PROG#OLC\MICR#M1~\2019\BUIL#ZPH\VC\Tools\MSVC\1428#Y8D.299\bin\Hostx64\x64\link.exe" /nologo CMakeFiles\cmTC_02d23.dir\testCCompiler.c.obj  /out:cmTC_02d23.exe /implib:cmTC_02d23.lib /pdb:cmTC_02d23.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 && cmd.exe /C "cd /D A:\Git\School\Driver\cmake-build-debug\CMakeFiles\CMakeTmp && C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy Bypass -file A:/Git/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary A:/Git/School/Driver/cmake-build-debug/CMakeFiles/CMakeTmp/cmTC_02d23.exe -installedDir A:/Git/vcpkg/installed/x64-windows-static/debug/bin -OutVariable out""
    LINK Pass 1: command "E:\PROG#OLC\MICR#M1~\2019\BUIL#ZPH\VC\Tools\MSVC\1428#Y8D.299\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_02d23.dir\testCCompiler.c.obj /out:cmTC_02d23.exe /implib:cmTC_02d23.lib /pdb:cmTC_02d23.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_02d23.dir/intermediate.manifest CMakeFiles\cmTC_02d23.dir/manifest.res" failed (exit code 1104) with the following output:
    LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
    ninja: build stopped: subcommand failed.
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:8 (project)

So my guess would be that CLion isn't able to find the correct Windows Kit that includes the missing static linked libs.


When working with VS2019 this issues is not existing as `LaunchBuildEnv.cmd` will take care of setting all paths.

Basically you just start `LaunchBuildEnv.cmd` then type `SetupVSEnv` and start VS2019 from the cmd and all paths etc. are fixed automatically.
Unfortunately this doesn't work for CLion. When pointing CLion to the `Build Tools` folder it is able to detect everything correctly but seems to no be able to get the Windows Kits from `E:\Program Files\Windows Kits\10`.

I already tried to supply CLion with `SetupBuildEnv.cmd` as the Environment File without any success.

So I wanted to ask if somebody know how I need to supply this path to CLion so it is correctly forwarded to cl.exe.

Regards Artur

7 comments
Comment actions Permalink

Hello!

Please go to File | Settings | Build, Execution, Deployment | CMake and paste the following options into the CMake options field:

-DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10

Does it help?

0
Comment actions Permalink

Anna Falevskaya

Thanks for the response but the flags didn't helped.

Is there any information that I could provide to you?

0
Comment actions Permalink

Please provide a screenshot of `File | Settings | Build, Execution, Deployment | Toolchains` (please capture the screenshot after the compiler detection is completed).

0
Comment actions Permalink

I really appreciate your help.

Here is the requested screenshot:

 

As far as I can tell the issue is caused by the generator I guess because then I switch to VS2019 as the generator everything works fine. Although I the compiler checks are then just skipped.

"C:\Program Files\JetBrains\CLion 2021.3.2\bin\cmake\win\bin\cmake.exe" -G "Visual Studio 16 2019" -DCMAKE_TOOLCHAIN_FILE=A:/Git/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static A:\Git\Driver
-- Selecting Windows SDK version  to target Windows 10.0.22000.
-- The C compiler identification is MSVC 19.28.29913.0
-- The CXX compiler identification is MSVC 19.28.29913.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: E:/Program Files/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: E:/Program Files/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found WDK: E:\Program Files\Windows Kits\10\/Include/10.0.22000.0/km/ntddk.h  
-- WDK_ROOT: E:/Program Files/Windows Kits/10
-- WDK_VERSION: 10.0.22000.0
-- Compilation date: 02/04/2022
-- Extended C++ features (exceptions, etc) are disabled for Driver
-- Configuring done
-- Generating done
-- Build files have been written to: A:/Git/Driver/cmake-build-debug

[Finished]

 

And when using ninja I get this:

"C:\Program Files\JetBrains\CLion 2021.3.2\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Program Files/JetBrains/CLion 2021.3.2/bin/ninja/win/ninja.exe" -G Ninja -DCMAKE_TOOLCHAIN_FILE=A:/Git/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static A:\Git\Driver

-- The C compiler identification is MSVC 19.28.29913.0

-- The CXX compiler identification is MSVC 19.28.29913.0

-- Detecting C compiler ABI info

-- Detecting C compiler ABI info - failed

-- Check for working C compiler: E:/Program Files/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe

-- Check for working C compiler: E:/Program Files/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - broken

CMake Error at C:/Program Files/JetBrains/CLion 2021.3.2/bin/cmake/win/share/cmake-3.21/Modules/CMakeTestCCompiler.cmake:69 (message):

  The C compiler

    "E:/Program Files/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: A:/Git/Driver/cmake-build-debug/CMakeFiles/CMakeTmp

   

    Run Build Command(s):C:/Program Files/JetBrains/CLion 2021.3.2/bin/ninja/win/ninja.exe cmTC_cd6e0 && [1/2] Building C object CMakeFiles\cmTC_cd6e0.dir\testCCompiler.c.obj

    [2/2] Linking C executable cmTC_cd6e0.exe

    FAILED: cmTC_cd6e0.exe

    cmd.exe /C "cd . && "C:\Program Files\JetBrains\CLion 2021.3.2\bin\cmake\win\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_cd6e0.dir --rc="E:\PROG#OLC\WIND#B-J\10\bin\1002#1AM.0\x86\rc.exe" --mt="E:\PROG#OLC\WIND#B-J\10\bin\1002#1AM.0\x86\mt.exe" --manifests  -- "E:\PROG#OLC\MICR#M1~\2019\BUIL#ZPH\VC\Tools\MSVC\1428#Y8D.299\bin\Hostx64\x64\link.exe" /nologo CMakeFiles\cmTC_cd6e0.dir\testCCompiler.c.obj  /out:cmTC_cd6e0.exe /implib:cmTC_cd6e0.lib /pdb:cmTC_cd6e0.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 && cmd.exe /C "cd /D A:\Git\Driver\cmake-build-debug\CMakeFiles\CMakeTmp && C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy Bypass -file A:/Git/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary A:/Git/Driver/cmake-build-debug/CMakeFiles/CMakeTmp/cmTC_cd6e0.exe -installedDir A:/Git/vcpkg/installed/x64-windows-static/debug/bin -OutVariable out""

    LINK Pass 1: command "E:\PROG#OLC\MICR#M1~\2019\BUIL#ZPH\VC\Tools\MSVC\1428#Y8D.299\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_cd6e0.dir\testCCompiler.c.obj /out:cmTC_cd6e0.exe /implib:cmTC_cd6e0.lib /pdb:cmTC_cd6e0.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_cd6e0.dir/intermediate.manifest CMakeFiles\cmTC_cd6e0.dir/manifest.res" failed (exit code 1104) with the following output:

    LINK : fatal error LNK1104: cannot open file 'kernel32.lib'

    ninja: build stopped: subcommand failed.

   

   




  CMake will not be able to correctly generate this project.

Call Stack (most recent call first):

  CMakeLists.txt:8 (project)

-- Configuring incomplete, errors occurred!

See also "A:/Git/Driver/cmake-build-debug/CMakeFiles/CMakeOutput.log".

See also "A:/Git/Driver/cmake-build-debug/CMakeFiles/CMakeError.log".

Problems were encountered while collecting compiler information:

    C:\Users\Artur\AppData\Local\Temp\compiler-file1144390587071832729: fatal error C1083: Cannot open include file: 'A:/Git/Driver/cmake-build-debug/CMakeFiles/wdkflags.h': No such file or directory

[Finished]
0
Comment actions Permalink

>As far as I can tell the issue is caused by the generator I guess because then I switch to VS2019 as the generator everything works fine. 

Is it ok for you to use this generator?

0
Comment actions Permalink

For sure, just wanted to let you know this if some other person has the same error.

Thanks for your time.

Have a nice weekend.

0
Comment actions Permalink

Thanks for sharing the solution! Hope you have a nice weekend too! 

0

Please sign in to leave a comment.