This question already has answers here:
Error while configuring CMake project: Running 'nmake' '-?' failed
(2 answers)
Closed 4 months ago.
When building with cmake on windows using Mingw64 we get errors like:
System cannot find the file specified
Log:
$ cmake ..
-- Building for: NMake Makefiles
CMake Error at CMakeLists.txt:72 (project):
Running
'nmake' '-?'
failed with:
The system cannot find the file specified
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "E:/MyTools/C/libs_download/cpp-httplib-0.11.2/build/CMakeFiles/CMakeOutput.log".
How to fix it?
This happens because cmake uses the Microsoft CMake format as default. The CMAKE_CXX_COMPILER not set here also indicates that we need to set the CMAKE_CXX_COMPILER variable to a c++ compiler path.
To fix we need to use the following command:
cmake -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CC_COMPILER=gcc -DCMAKE_MAKE_PROGRAM=mingw32-make -G "MinGW Makefiles" ..
Here we provide the following flags:
CMAKE_CXX_COMPILER=g++ - Use g++ as C++ compiler (or provide full path)
CMAKE_CC_COMPILER=gcc - Use gcc as C compiler
CMAKE_MAKE_PROGRAM=mingw32-make - Use mingw32-make as the make program
-G "MinGW Makefiles" - Use the MinGW Makefile format not Microsoft makefile format
After this you can run mingw32-make as usual instead of make to build :)
Related
This question already has answers here:
CMake: The C Compiler is not able to compile a simple test program
(4 answers)
Linker error on a C project using Eclipse
(5 answers)
How to cross compile with cmake + arm-none-eabi on windows?
(1 answer)
Closed 1 year ago.
I am trying to use arm-none-eabi-gcc with CMake but am getting an error about an undefined reference to "_exit". The following is the terminal output after running cmake (the first line is the command):
cmake --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=F:\Resources\Dev\Tools\GNU-arm\10.3-2021.07\bin\arm-none-eabi-gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=F:\Resources\Dev\Tools\GNU-arm\10.3-2021.07\bin\arm-none-eabi-g++.exe -Hf:/Projects/Dev/VS-Code/CPP/CPP-Sandbox "-Bf:/Projects/Dev/VS-Code/CPP/CPP-Sandbox/build/GCC 10.3.1 arm-none-eabi/Debug" -G Ninja
Not searching for unused variables given on the command line.
-- The C compiler identification is GNU 10.3.1
-- Check for working C compiler: F:/Resources/Dev/Tools/GNU-arm/10.3-2021.07/bin/arm-none-eabi-gcc.exe
-- Check for working C compiler: F:/Resources/Dev/Tools/GNU-arm/10.3-2021.07/bin/arm-none-eabi-gcc.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"F:/Resources/Dev/Tools/GNU-arm/10.3-2021.07/bin/arm-none-eabi-gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: F:/Projects/Dev/VS-Code/CPP/CPP-Sandbox/build/GCC 10.3.1 arm-none-eabi/Debug/CMakeFiles/CMakeTmp
Run Build Command(s):F:/Resources/Dev/Tools/MinGW/MinGW-9.0.0-x64/bin/ninja.exe cmTC_1a12b && [1/2] Building C object CMakeFiles/cmTC_1a12b.dir/testCCompiler.c.obj
[2/2] Linking C executable cmTC_1a12b
FAILED: cmTC_1a12b
cmd.exe /C "cd . && F:\Resources\Dev\Tools\GNU-arm\10.3-2021.07\bin\arm-none-eabi-gcc.exe CMakeFiles/cmTC_1a12b.dir/testCCompiler.c.obj -o cmTC_1a12b && cd ."
f:/resources/dev/tools/gnu-arm/10.3-2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: f:/resources/dev/tools/gnu-arm/10.3-2021.07/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/lib\libc.a(lib_a-exit.o): in function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:41 (project)
-- Configuring incomplete, errors occurred!
See also "F:/Projects/Dev/VS-Code/CPP/CPP-Sandbox/build/GCC 10.3.1 arm-none-eabi/Debug/CMakeFiles/CMakeOutput.log".
See also "F:/Projects/Dev/VS-Code/CPP/CPP-Sandbox/build/GCC 10.3.1 arm-none-eabi/Debug/CMakeFiles/CMakeError.log".
I have tried the following solution (i.e. adding simply adding -specs=nosys.specs to my CMakeLists.txt but to no avail. Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_C_STANDARD 99)
# Project variables
set(LOCAL_PROJECT_NAME "C-Sandbox")
set(LOCAL_PROJECT_VERSION "0.0.1")
set(LOCAL_PROJECT_DESCRIPTION "Description")
# Project setup
project(${LOCAL_PROJECT_NAME}
VERSION ${LOCAL_PROJECT_VERSION}
DESCRIPTION ${LOCAL_PROJECT_DESCRIPTION}
LANGUAGES C)
add_executable(${LOCAL_PROJECT_NAME})
target_sources(${LOCAL_PROJECT_NAME} PRIVATE src/main.c)
target_link_options(${LOCAL_PROJECT_NAME} PRIVATE "-specs=nosys.specs")
set_target_properties(${LOCAL_PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "bin")
Edit:
When I cd into my source folder and run arm-none-eabi-gcc main.c -lc "-specs=nosys.specs" I get no error and an a.out file.
I'm running a conda environment on Windows to get a bash-similar environment (I'm a native Linux Mint user and this is my first time running Windows). But when I run cmake in my conda environment I get the following error:
-- Building for: NMake Makefiles
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:33 (project):
The CMAKE_C_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell
that can use the compiler cl from the command line. This environment is
unable to invoke the cl compiler. To fix this problem, run cmake from the
Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:33 (project):
The CMAKE_CXX_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell
that can use the compiler cl from the command line. This environment is
unable to invoke the cl compiler. To fix this problem, run cmake from the
Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "C://CMakeFiles/CMakeOutput.log".
See also "C://CMakeFiles/CMakeError.log".
CMake Error: Cannot open file for write: C://CMakeCache.txt.tmp
CMake Error: : System Error: Permission denied
CMake Error: Unable to open cache file for save. C://CMakeCache.txt
CMake Error: : System Error: Permission denied
I've installed GCC on my conda environment, but I'm not sure how to force CMake to find it.
UPDATE:
I was able to point the compiler to where gcc is installed, but now I get this error:
-- Building for: NMake Makefiles
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: C:/Users/aeglick/AppData/Local/Continuum/anaconda2/Library/mingw-w64/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: nmake /nologo cmTC_da93e\fast &&
-- Check for working C compiler: C:/Users/aeglick/AppData/Local/Continuum/anaconda2/Library/mingw-w64/bin/gcc.exe - broken
CMake Error at C:/Users/aeglick/AppData/Local/Continuum/anaconda2/Library/share/cmake-3.17/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"C:/Users/aeglick/AppData/Local/Continuum/anaconda2/Library/mingw-w64/bin/gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/aeglick/Documents/GEANT4.10.07/geant4-build/CMakeFiles/CMakeTmp
Run Build Command(s):nmake /nologo cmTC_da93e\fast && The system cannot find the file specified
Generator: execution of make failed. Make command was: nmake /nologo cmTC_da93e\fast &&
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:33 (project)
-- Configuring incomplete, errors occurred!
See also "C:/Users/aeglick/Documents/GEANT4.10.07/geant4-build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/aeglick/Documents/GEANT4.10.07/geant4-build/CMakeFiles/CMakeError.log".
I am trying to build OpenBLAS from here, following these instructions. After running
cmake .. -G "Ninja" -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_C_COMPILER=clang-cl -DCMAKE_Fortran_COMPILER=flang -DBUILD_WITHOUT_LAPACK=no -DNOFORTRAN=0 -DDYNAMIC_ARCH=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
The error generated is:
-- The C compiler identification is unknown
-- The ASM compiler identification is unknown
-- Didn't find assembler
CMake Error at CMakeLists.txt:6 (project):
The CMAKE_C_COMPILER:
clang-cl
is not a full path and was not found in the PATH.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:6 (project):
No CMAKE_ASM_COMPILER could be found.
Tell CMake where to find the compiler by setting either the environment
variable "ASM" or the CMake cache entry CMAKE_ASM_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Warning: Did not find file Compiler/-ASM
-- Configuring incomplete, errors occurred!
See also "D:/OpenBLAS_0.3.10/xianyi-OpenBLAS-63b03ef/build/CMakeFiles/CMakeOutput.log".
See also "D:/OpenBLAS_0.3.10/xianyi-OpenBLAS-63b03ef/build/CMakeFiles/CMakeError.log".
After a bit of googling, I found this webpage: Assembler
It does not specify how to resolve this issue. How to solve it?
Here's the error I'm getting:
-- Building for: NMake Makefiles
-- The C compiler identification is GNU 4.8.1
-- The CXX compiler identification is GNU 4.8.1
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_86068\fast"
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.4/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "C:/MinGW/bin/gcc.exe" is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/--REDACTED--/CMakeFiles/CMakeTmp
Run Build Command:"nmake" "/NOLOGO" "cmTC_86068\fast"
The system cannot find the file specified
Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_86068\fast"
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:/--REDACTED--/socket.io-client-cpp-1.6.1/CMakeFiles/CMakeOutput.log".
See also "C:/--REDACTED--/socket.io-client-cpp-1.6.1/CMakeFiles/CMakeError.log".
For the record I am using:
gcc and g++ from MinGW 4.8.1
CMake 3.4.1
I have no idea what the issue could be, I've looked extensively online and have not found anywhere where somebody has gotten a solution, except in cases where it had to do with path issues where the path included non-latin characters or no write access, which is not the case for any of the directories in question. I seriously am about to give up completely on ever being able to get this to work, but I don't know what to do because I absolutely NEED the socket.io client for C++ for this project.
CMake is a utility which generates a "makefile" for different build systems. Here you generate a nmake makefile and it seems that you don't have nmake in your path.
You can launch CMake with option -G "MinGW Makefiles" in order to generate a makefile compatible with mingw make. Then issue the command:
mingw32-make
On Windows 10, with an installed msys2, which is a variant of mingw, I have an installed cmake with the gcc toolchain and all the standard tools like make.
The version of g++ is 6.2 and make is 4.2.1 Both are in the path.
When I build using cmake:
cmake .
it tries to build using nmake and cl. So somehow because I am on windows cmake is trying to use the visual studio toolchain.
export CMAKE_CXX_COMPILER=g++
does not help. The error is:
-- Building for: NMake Makefiles
-- The C compiler identification is unknown
-- The CXX compiler identification is Clang 3.8.0
-- Check for working C compiler: D:/msys64/mingw64/bin/clang++.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_87e5f\fast"
-- Check for working C compiler: D:/msys64/mingw64/bin/clang++.exe -- broken
CMake Error at D:/msys64/mingw64/share/cmake-3.6/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "D:/msys64/mingw64/bin/clang++.exe" is not able to compile a
simple test program.
It fails with the following output:
Change Dir: D:/git/CSP/CMakeFiles/CMakeTmp
Run Build Command:"nmake" "/NOLOGO" "cmTC_87e5f\fast"
Generator: execution of make failed. Make command was: "nmake" "/NOLOGO"
"cmTC_87e5f\fast"
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 "D:/git/CSP/CMakeFiles/CMakeOutput.log".
See also "D:/git/CSP/CMakeFiles/CMakeError.log".
To use MSYS2 toolchain, you need to specify the build system generator explicitly, i.e.
cmake -G 'MSYS Makefiles' .
Additional note, it's a good practice to separate the application . source file and cmake's generated file, e.g.
mkdir build
cd build
cmake -G 'MSYS Makefiles' ..