Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake "NMake Makefiles" generator fails to compile

I'm compiling simple application from this tutorial: https://www.johnlamp.net/cmake-tutorial-1-getting-started.html (just main.cc, ToDo.cc and ToDo.h files).

I have Visual Studio 2015 installed and when I use it's generator, VS project is generated successfully:

PS C:\data\OtherTech\cmaketest\build> cmake "Visual Studio 14 2015" ..

However, if I use "NMake Makefiles" or "Unix Makefiles" generators:

PS C:\data\OtherTech\cmaketest\build> cmake "NMake Makefiles" ..

I'm getting the following error:

> PS C:\data\OtherTech\cmaketest\build> cmake -G "NMake Makefiles" ..
-- The C compiler identification is MSVC 19.0.23026.0
-- The CXX compiler identification is MSVC 19.0.23026.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe -- broken
CMake Error at C:/Users/user1/Desktop/Apps/cmake-3.4.0-win32-x86/share/cmake-3.4/Modules/CMakeTestCCompiler.cmake:61 (
message):
  The C compiler "C:/Program Files (x86)/Microsoft Visual Studio
  14.0/VC/bin/cl.exe" is not able to compile a simple test program.

  It fails with the following output:

   Change Dir: C:/Data/OtherTech/cmaketest/build/CMakeFiles/CMakeTmp



  Run Build Command:"nmake" "/NOLOGO" "cmTC_6fd86\fast"

        "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\nmake.exe" -f
  CMakeFiles\cmTC_6fd86.dir\build.make /nologo -L
  CMakeFiles\cmTC_6fd86.dir\build

  Building C object CMakeFiles/cmTC_6fd86.dir/testCCompiler.c.obj

        C:\PROGRA~2\MICROS~3.0\VC\bin\cl.exe
  @C:\Users\user1\AppData\Local\Temp\nm5A8B.tmp

  testCCompiler.c

  Linking C executable cmTC_6fd86.exe

        C:\Users\user1\Desktop\Apps\cmake-3.4.0-win32-x86\bin\cmake.exe -E
  vs_link_exe --intdir=CMakeFiles\cmTC_6fd86.dir --manifests --
  C:\PROGRA~2\MICROS~3.0\VC\bin\link.exe /nologo
  @CMakeFiles\cmTC_6fd86.dir\objects1.rsp
  @C:\Users\user1\AppData\Local\Temp\nm5B29.tmp

  The parameter is incorrectRC Pass 1 failed to run.

  NMAKE : fatal error U1077:
  'C:\Users\user1\Desktop\Apps\cmake-3.4.0-win32-x86\bin\cmake.exe' :
  return code '0xffffffff'

  Stop.

  NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio
  14.0\VC\bin\nmake.exe"' : return code '0x2'

  Stop.





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


-- Configuring incomplete, errors occurred!
See also "C:/Data/OtherTech/cmaketest/build/CMakeFiles/CMakeOutput.log".
See also "C:/Data/OtherTech/cmaketest/build/CMakeFiles/CMakeError.log".

Also, if I look at CMakeFiles\CMakeError.log

it contains error:

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

here is full output:

    Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe 
Build flags: 
Id flags: 

The output was:
2
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23026 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

CMakeCCompilerId.c
Microsoft (R) Incremental Linker Version 14.00.23026.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:CMakeCCompilerId.exe 
CMakeCCompilerId.obj 
LINK : fatal error LNK1104: cannot open file 'LIBCMT.lib'


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/cl.exe 
Build flags: 
Id flags: 

The output was:
2
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23026 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

CMakeCXXCompilerId.cpp
Microsoft (R) Incremental Linker Version 14.00.23026.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:CMakeCXXCompilerId.exe 
CMakeCXXCompilerId.obj 
LINK : fatal error LNK1104: cannot open file 'LIBCMT.lib'


Determining if the C compiler works failed with the following output:
Change Dir: C:/Data/OtherTech/cmaketest/build/CMakeFiles/CMakeTmp

Run Build Command:"nmake" "/NOLOGO" "cmTC_6fd86\fast"
    "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\nmake.exe" -f CMakeFiles\cmTC_6fd86.dir\build.make /nologo -L                  CMakeFiles\cmTC_6fd86.dir\build

Building C object CMakeFiles/cmTC_6fd86.dir/testCCompiler.c.obj

    C:\PROGRA~2\MICROS~3.0\VC\bin\cl.exe  @C:\Users\user1\AppData\Local\Temp\nm5A8B.tmp

testCCompiler.c

Linking C executable cmTC_6fd86.exe

    C:\Users\user1\Desktop\Apps\cmake-3.4.0-win32-x86\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_6fd86.dir --manifests  -- C:\PROGRA~2\MICROS~3.0\VC\bin\link.exe /nologo @CMakeFiles\cmTC_6fd86.dir\objects1.rsp @C:\Users\user1\AppData\Local\Temp\nm5B29.tmp

The parameter is incorrectRC Pass 1 failed to run.

NMAKE : fatal error U1077: 'C:\Users\user1\Desktop\Apps\cmake-3.4.0-win32-x86\bin\cmake.exe' : return code '0xffffffff'

Stop.

NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\nmake.exe"' : return code '0x2'

Stop.

I was searching for information about this error and figured out that perhaps my PowerShell session does not have access to some environment variables, so I went to C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC and run

.\vcvarsall.bat

to configure the environment, but this unfortunately didn't help.

Any ideas how to fix this issue?

like image 980
Bart Avatar asked Nov 20 '15 00:11

Bart


People also ask

Does CMake work with makefiles?

CMake is a generator of buildsystems. It can produce Makefiles, it can produce Ninja build files, it can produce KDEvelop or Xcode projects, it can produce Visual Studio solutions.

What are nmake Makefiles?

The Microsoft Program Maintenance Utility (NMAKE. EXE) is a command-line tool included with Visual Studio. It builds projects based on commands that are contained in a description file, usually called a makefile. NMAKE must run in a Developer Command Prompt window.

What is CMakeLists TXT and Makefile?

The CMakeLists.txt file contains a set of directives and instructions describing the source and targets. Unlike a complex Makefile that looks intimidating to a beginner, a CMakeLists.txt file is more structured and well written. This is owing to the well defined cmake-language with which the CMakeLists.txt are written.


2 Answers

Run cmake or cmake-gui from a Visual Studio Native Tools Command Prompt and not a plain command prompt. That way all the required paths are correctly setup and visible to cmake.

like image 133
acraig5075 Avatar answered Sep 21 '22 07:09

acraig5075


I faced the same issue.

Solution:

before running cmake -G "NMake Makefiles", execute VC Path\vcvarsall.bat first in CMD.

PS: Only work in CMD, won't work in PowerShell.

like image 38
JustWe Avatar answered Sep 23 '22 07:09

JustWe