3

I have an existing project that I didn't know how to create a vs solution from it. So I decided to use KDevelop which can parse the directory and use the CMakeLists.txt.

The thing is that cmake can't find some lib files for the linking. The directory that these files are stored is in PATH. At first I thought that I might be compiling for another ARCH but I don't know where to go from here.

    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 ***
```

Are there any ideas on what could be wrong?

EDIT : SOLVED

At last I found a rather hackish workaround. The batch file for KDevelop in VS enviroment, doesn't work for VS-2017 (which defined the VS150COMNTOOLS variable) but it supports up to VS-2015 (VS140COMNTOOLS).

VS2017 changed the layout of it's folders so the old SET script="!base!\..\..\VC\vcvarsall.bat" really becomes SET script="%base%..\..\VC\Auxiliary\Build\vcvarsall.bat" x64.

Of course this new script should be run inside Developer Command Prompt console and not by just clicking the batch file.

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"
Petross404
  • 177
  • 1
  • 12
  • Try deleting `build` directory from the project's root and then running KDevelop in Visual Studio environment (there is a link for that). – arrowd Oct 01 '18 at 06:21
  • Yeah that's what I am doing but without luck. I found out that cmake doens't find MSVC. – Petross404 Oct 01 '18 at 06:45
  • Yep, so it is not KDevelop problem. Try running `Visual Studio Installer`, making sure everything is up-to-date and C++ components are installed. – arrowd Oct 01 '18 at 07:16
  • I think it's a `PATH` issue because now running `cl` from `Developer Command Prompt` gives me an error of [`application was unable to start correctly 0xc000007b`](https://social.msdn.microsoft.com/Forums/vstudio/en-US/122b22d7-0888-471a-b834-1c4c338679ff/clexe-failing-with-application-was-unable-to-start-correctly-0xc000007b?forum=vcgeneral). Thank you :) – Petross404 Oct 01 '18 at 10:55
  • Error `0xc000007b` disappeared as soon as I took care of the messed up `PATH` and logoff. – Petross404 Oct 01 '18 at 20:47
  • @Petross404: Could you file a patch for this? Please see https://www.kdevelop.org/contribute-kdevelop how to submit one. – kfunk Oct 05 '18 at 08:18
  • @kfunk : Well, I can try. – Petross404 Oct 05 '18 at 20:17

0 Answers0