KDevelop(Win7)下的NMake:错误LNK1104:无法打开文件'kernel32.lib'

时间:2018-09-29 22:40:35

标签: visual-c++ cmake linker-errors nmake kdevelop

我有一个现有项目,但我不知道如何从中创建vs解决方案。因此,我决定使用KDevelop,它可以解析目录并使用CMakeLists.txt

问题是cmake找不到用于链接的某些lib文件。这些文件的存储目录位于PATH中。起初,我以为我可能正在编译另一个ARCH,但是我不知道从这里开始。

    C:/Users/Petros/projects/QtDice/build> "C:/Program Files/CMake/bin/cmake.exe" "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" "-DCMAKE_INSTALL_PREFIX=C:/Program Files (x86)/QtDice" "-DCMAKE_BUILD_TYPE=Debug" C:/Users/Petros/projects/QtDice
-- The CXX compiler identification is MSVC 19.15.26730.0
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/bin/Hostx64/x64/cl.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/CMakeTestCXXCompiler.cmake:45 (message):
  The C++ compiler

    "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/bin/Hostx64/x64/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/Users/Petros/projects/QtDice/build/CMakeFiles/CMakeTmp

    Run Build Command:"nmake" "/nologo" "cmTC_c2fa6\fast"
        "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\nmake.exe" -f CMakeFiles\cmTC_c2fa6.dir\build.make /nologo -L                  CMakeFiles\cmTC_c2fa6.dir\build
    Building CXX object CMakeFiles/cmTC_c2fa6.dir/testCXXCompiler.cxx.obj
        C:\PROGRA~2\MICROS~3\2017\COMMUN~1\VC\Tools\MSVC\1415~1.267\bin\Hostx64\x64\cl.exe @C:\Users\Petros\AppData\Local\Temp\nm8F3F.tmp
    testCXXCompiler.cxx
    Linking CXX executable cmTC_c2fa6.exe
        "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_c2fa6.dir --manifests  -- C:\PROGRA~2\MICROS~3\2017\COMMUN~1\VC\Tools\MSVC\1415~1.267\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\cmTC_c2fa6.dir\objects1.rsp @C:\Users\Petros\AppData\Local\Temp\nm9088.tmp
    LINK Pass 1: command "C:\PROGRA~2\MICROS~3\2017\COMMUN~1\VC\Tools\MSVC\1415~1.267\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\cmTC_c2fa6.dir\objects1.rsp /out:cmTC_c2fa6.exe /implib:cmTC_c2fa6.lib /pdb:C:\Users\Petros\projects\QtDice\build\CMakeFiles\CMakeTmp\cmTC_c2fa6.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_c2fa6.dir/intermediate.manifest CMakeFiles\cmTC_c2fa6.dir/manifest.res" failed (exit code 1104) with the following output:
    LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
    NMAKE : fatal error U1077: '"C:\Program Files\CMake\bin\cmake.exe"' : return code '0xffffffff'
    Stop.
    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\HostX64\x64\nmake.exe"' : return code '0x2'
    Stop.




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


-- Configuring incomplete, errors occurred!
See also "C:/Users/Petros/projects/QtDice/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/Petros/projects/QtDice/build/CMakeFiles/CMakeError.log".
*** Failure: Exit code 1 ***
```

关于可能出什么问题有任何想法吗?

编辑:已解决

最后,我发现了一个相当棘手的解决方法。 VS环境中KDevelop的批处理文件不适用于VS-2017(定义了VS150COMNTOOLS变量),但最多支持VS-2015(VS140COMNTOOLS)。

VS2017更改了文件夹的布局,因此旧的SET script="!base!\..\..\VC\vcvarsall.bat"真正变成了SET script="%base%..\..\VC\Auxiliary\Build\vcvarsall.bat" x64

当然,此新脚本应在Developer Command Prompt控制台中运行,而不仅仅是单击批处理文件。

setlocal EnableDelayedExpansion
setlocal enableextensions

if DEFINED VS150COMNTOOLS (
    SET "base=%VS150COMNTOOLS%"
) else ( IF DEFINED VS120COMNTOOLS (
    SET "base=%VS120COMNTOOLS%"
) else ( IF DEFINED VS110COMNTOOLS (
    SET "base=%VS110COMNTOOLS%"
) else ( IF DEFINED VS100COMNTOOLS (
    SET "base=%VS100COMNTOOLS%"
) else (
    START CMD /C "The Microsoft Visual C++ compiler was not found on your system, you might not be able to compile programs. && PAUSE"
) )))

SET script="%base%..\..\VC\Auxiliary\Build\vcvarsall.bat" x64
CALL %script%

FOR /F "usebackq tokens=3*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\Software\KDE\KDevelop" /v Install_Dir`) DO (
    set appdir=%%A %%B
)

if NOT DEFINED appdir (
    FOR /F "usebackq tokens=3*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\Software\Wow6432Node\KDE\KDevelop" /v Install_Dir`) DO (
        set appdir=%%A %%B
    )
)

START "" "%appdir%\bin\kdevelop.exe"

0 个答案:

没有答案