“LNK1104无法打开文件'kernel32.lib'”时尝试在CMAKE中配置项目

"LNK1104 Cannot open file 'kernel32.lib' " when trying to Configure project in CMAKE

提问人:Violeta Ayon 提问时间:10/23/2023 最后编辑:Violeta Ayon 更新时间:10/23/2023 访问量:77

问:

我正在尝试使用 Visual Studio 17 2022 在 x64 中在 CMAKE 中配置 C、C++、Fortran 项目,如果我按原样运行它,首先会出现此错误:

Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19044.
The CXX compiler identification is MSVC 19.37.32825.0
The C compiler identification is MSVC 19.37.32825.0
The Fortran compiler identification is unknown
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe - skipped
Detecting CXX compile features
Detecting CXX compile features - done
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe - skipped
Detecting C compile features
Detecting C compile features - done
CMake Error at CMakeLists.txt:4 (project):
  No CMAKE_Fortran_COMPILER could be found.



Configuring incomplete, errors occurred!

我通过在CMAKE上设置编译器所在的路径来修复此错误:

CMAKE_Fortran_COMPILER="C:/Program Files (x86)/Intel/oneAPI/compiler/2023.2.0/windows"

然后我尝试再次配置项目(首先删除缓存):

CMake Error at C:/Program Files/CMake/share/cmake-3.26/Modules/CMakeTestFortranCompiler.cmake:59 (message):
  The Fortran compiler

    "C:/Program Files (x86)/Intel/oneAPI/compiler/2023.2.0/windows"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/workspace/siesta.core/build/CMakeFiles/CMakeScratch/TryCompile-yywg1p
    
    Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Professional/Common7/IDE/devenv.com CMAKE_TRY_COMPILE.sln /build Debug /project cmTC_cd35e && 

    Microsoft Visual Studio 2022 Version 17.7.5.

    Copyright (C) Microsoft Corp. All rights reserved.

    Build started...

    1>------ Build started: Project: cmTC_cd35e, Configuration: Debug x64 ------

    Compiling with Intelr Fortran Compiler Classic 2021.10.0 [Intel(R) 64]...

    testFortranCompiler.f

    Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.10.0 Build 20230609_000000

    Copyright (C) 1985-2023 Intel Corporation.  All rights reserved.

    Compiling manifest to resources...

    Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

    Copyright (C) Microsoft Corporation.  All rights reserved.

    Linking...

    Microsoft (R) Incremental Linker Version 14.37.32825.0

    Copyright (C) Microsoft Corporation.  All rights reserved.

    /OUT:C:\workspace\test.core\build\CMakeFiles\CMakeScratch\TryCompile-yywg1p\Debug\cmTC_cd35e.exe

    /VERSION:0.0

    /MANIFEST

    /MANIFESTFILE:cmTC_cd35e.dir\Debug\cmTC_cd35e.exe.intermediate.manifest

    "/MANIFESTUAC:level='asInvoker' uiAccess='false'"

    /SUBSYSTEM:CONSOLE

    /IMPLIB:C:\workspace\test.core\build\CMakeFiles\CMakeScratch\TryCompile-yywg1p\Debug\cmTC_cd35e.lib

    /machine:x64

    cmTC_cd35e.dir\Debug\testFortranCompiler.obj

    cmTC_cd35e.dir\Debug\cmTC_cd35e.exe.embed.manifest.res

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

TL;DR:链接:致命错误LNK1104:无法打开文件“kernel32.lib”

当我打开在 Visual Studio 上创建的 fortran 项目 (.vfproj) 时,我在其中转到“项目属性”>“配置属性”>“链接器”>“常规”>“其他库目录”,然后添加 kernel32.lib 所在的文件夹,然后再次尝试在 VS 中构建项目,它有效并且LNK1104错误消失了。

我不确定如何复制此解决方案,但在 CMAKE 中, 我看到一个可能的解决方案是在 CMakeLists.txt 文件中使用名为“target_link_libraries(your_target_name kernel32.lib)”的命令,但我宁愿不修改 CMakeLists.txt 文件,因为它被很多人使用,我必须保存更改。运行 cmake 时,可以在控制台中使用命令。

我还想补充一点,我多次尝试卸载和安装 VS2022,还有英特尔 Fortran 编译器,但发生了同样的错误(kernel32.lib 错误)。我确实在 VS 安装程序中安装了使用 C++ 选项的桌面开发。还有 Windows 11 SDK。

感谢您的帮助!

Windows Visual-Studio CMake 英特尔-Fortran

评论

0赞 Violeta Ayon 10/23/2023
我有这些 PATH 变量: C:\Program Files (x86)\Intel\oneAPI\ C:\Program Files (x86)\Intel\oneAPI\mpi\latest\bin\release\ C:\Program Files (x86)\Intel\oneAPI\mpi\latest\libfabric\bin\ C:\Program Files (x86)\Intel\oneAPI\mpi\latest\libfabric\bin\utils\ C:\Program Files (x86)\Intel\oneAPI\tbb\latest\redist\intel64\vc_mt\ C:\Program Files (x86)\Intel\oneAPI\tbb\latest\redist\ia32\vc_mt\ C:\程序文件 (x86)\Intel\oneAPI\compiler\latest\windows\redist\intel64_win\compiler C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\redist\ia32_win\compiler C:\Program Files\CMake\bin

答: 暂无答案