I am building a C++ project with Clang 3.8 and CMake 3.7 on Windows, but Clang emits an error in configure like below.
Determining if the CXX compiler works failed with the following output:
Change Dir: C:/tools/k.build/CMakeFiles/CMakeTmp
Run Build Command:"C:/tools/ninja.exe" "cmTC_c0004"
[1/2] Building CXX object CMakeFiles/cmTC_c0004.dir/testCXXCompiler.cxx.obj
[2/2] Linking CXX executable cmTC_c0004.exe
FAILED: cmTC_c0004.exe
cmd.exe /C "cd . && C:\tools\llvm-3.8.1.build\Release\bin\clang++.exe CMakeFiles/cmTC_c0004.dir/testCXXCompiler.cxx.obj -o cmTC_c0004.exe -Wl,--out-implib,libcmTC_c0004.dll.a -Wl,--major-image-version,0,--minor-image-version,0 && cd ."
LINK : warning LNK4044: unrecognized option '/-out-implib'; ignored
LINK : warning LNK4044: unrecognized option '/-major-image-version'; ignored
LINK : warning LNK4044: unrecognized option '/-minor-image-version'; ignored
LINK : fatal error LNK1181: cannot open input file 'libcmTC_c0004.dll.a'
clang++.exe: error: linker command failed with exit code 1181 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Strange thing is that no file exists in CMakeFiles/CMakeTmp/. How can I get it to work?
Simply put, you are defining your toolchain wrong. CMake thinks you are using the MSVC compiler with a different path. See this question for a detailed answer. Note that you will still need MSVC or Cygwin as a build environment.
Related
I am trying to Build OpenCascade from source.
I am using this guide:
https://github.com/tpaviot/oce/blob/master/BUILD.MINGWw64.md
All the steps from 1-5, which include downloading stuff have been performed.
Now i am trying to build using CMAKE
*I used "Where is the source code" option to point to the directory of the oce (as instructed).
*I used "Where to build the binaries" option, to point the a folder which i named 'BUILD' inside the directory mentioned in the above step (as instructed).
*I pressed 'Configure' and selected "MSYS Makefiles" with default native compilers.
Here started the errors.
I noticed that CMake had produced a text file, so i went inside and changed the CMAKE MAKE location: CMAKE_MAKE_PROGRAM:FILEPATH=C:/Users/User1/Desktop/OPENCA~1/msys/bin
There i moved forward but new errors spawned.
so how do i move forward?
The guide then says:
"
Check OCE_USE_BUNDLE_SOURCE
Check OCE_WITH_FREEIMAGE
Check OCE_WITH_GL2PS
Check OCE_VISUALISATION
"
Where do i set these?
There are no such variables inside the text file, and neither i can set them up on CMAKE.
EDIT:
These are the errors i get now:
The C compiler identification is GNU 8.1.0
The CXX compiler identification is GNU 8.1.0
Detecting C compiler ABI info
CMake Error: Generator: execution of make failed. Make command was: C:/Users/User1/Desktop/OPENCA~1/msys/bin cmTC_a5bfb/fast &&
Detecting C compiler ABI info - failed
Check for working C compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: C:/Users/User1/Desktop/OPENCA~1/msys/bin cmTC_d3ad7/fast &&
Check for working C compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.18/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
"C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/User1/Desktop/OpenCascade project/oce/BUILD/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Users/User1/Desktop/OPENCA~1/msys/bin cmTC_d3ad7/fast && Access is denied
Generator: execution of make failed. Make command was: C:/Users/User1/Desktop/OPENCA~1/msys/bin cmTC_d3ad7/fast &&
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:20 (project)
Configuring incomplete, errors occurred!
See also "C:/Users/User1/Desktop/OpenCascade project/oce/BUILD/CMakeFiles/CMakeOutput.log".
See also "C:/Users/User1/Desktop/OpenCascade project/oce/BUILD/CMakeFiles/CMakeError.log".
EDIT 2:
There are some null options in CMake:
EDIT 3:
After following the advice of Tsyvarev, i changed the line to
CMAKE_MAKE_PROGRAM:FILEPATH=C:/Users/User1/Desktop/OPENCA~1/msys/bin/make.exe
These are the errors i get:
The C compiler identification is GNU 8.1.0
The CXX compiler identification is GNU 8.1.0
Detecting C compiler ABI info
CMake Error: Generator: execution of make failed. Make command was: C:/Users/User1/Desktop/OPENCA~1/msys/bin cmTC_51dc6/fast &&
Detecting C compiler ABI info - failed
Check for working C compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: C:/Users/User1/Desktop/OPENCA~1/msys/bin cmTC_88ba8/fast &&
Check for working C compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.18/Modules/CMakeTestCCompiler.cmake:66 (message):
The C compiler
"C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/User1/Desktop/OpenCascade project/oce/BUILD/CMakeFiles/CMakeTmp
Run Build Command(s):C:/Users/User1/Desktop/OPENCA~1/msys/bin cmTC_88ba8/fast && Access is denied
Generator: execution of make failed. Make command was: C:/Users/User1/Desktop/OPENCA~1/msys/bin cmTC_88ba8/fast &&
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:20 (project)
Configuring incomplete, errors occurred!
See also "C:/Users/User1/Desktop/OpenCascade project/oce/BUILD/CMakeFiles/CMakeOutput.log".
See also "C:/Users/User1/Desktop/OpenCascade project/oce/BUILD/CMakeFiles/CMakeError.log".
Here's how I built OpenCascade 7.4.0 (static+shared) from http://www.opencascade.com/content/latest-release under MSYS2 using Ninja:
INSTALLPREFIX=/usr/local
mkdir -p build_static build_shared &&
cmake.exe -Wno-dev -GNinja -DCMAKE_INSTALL_PREFIX:PATH=$INSTALLPREFIX/share/opencascade -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_LIBRARY_TYPE:STRING=Static -DUSE_VTK:BOOL=OFF -DUSE_RAPIDJSON:BOOL=ON -DUSE_FREEIMAGE:BOOL=OFF -DUSE_FFMPEG:BOOL=OFF -DUSE_D3D:BOOL=OFF -DBUILD_RELEASE_DISABLE_EXCEPTIONS:BOOL=ON -DBUILD_USE_PCH:BOOL=OFF -DBUILD_SAMPLES_QT:BOOL=OFF -S. -Bbuild_static &&
cmake.exe -Wno-dev -GNinja -DCMAKE_INSTALL_PREFIX:PATH=$INSTALLPREFIX/share/opencascade -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=ON -DBUILD_LIBRARY_TYPE:STRING=Shared -DUSE_VTK:BOOL=OFF -DUSE_RAPIDJSON:BOOL=ON -DUSE_FREEIMAGE:BOOL=OFF -DUSE_FFMPEG:BOOL=OFF -DUSE_D3D:BOOL=OFF -DBUILD_RELEASE_DISABLE_EXCEPTIONS:BOOL=ON -DBUILD_USE_PCH:BOOL=OFF -DBUILD_SAMPLES_QT:BOOL=OFF -S. -Bbuild_shared &&
sed -i.bak -e "s/LINK_LIBRARIES *= *[^ ]*libTKTopAlgo\.dll\.a.*-lfreetype.*libTKernel\.dll\.a.*$/& -Wl,--as-needed -lz -lbz2 -lharfbuzz -lpng -lbrotlidec/" build_shared/build.ninja &&
ninja -Cbuild_static install/strip &&
ninja -Cbuild_shared install/strip &&
echo Success
When I create new project in Clion, cmake cannot find CMakeTmp directory.
Run Build Command(s):/usr/bin/cmake cmTC_df723/fast && No such file or directory
OS: Linux Mint 19 (Ubuntu based)
I have tried:
reinstalling gcc (now on version 8.3.0)
reinstalling cmake (now on version 3.15.2)
unset TMP from (CMake cannot compile test program as source directory doesnt exist)
set(CMAKE_C_COMPILER gcc)
set(CMAKE_SYSTEM_NAME Linux)
checked permissions to ClionProject subdirectories
Error output:
/usr/local/bin/cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=/usr/bin/cmake -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/c++ -DCMAKE_C_COMPILER=/usr/bin/gcc -G "CodeBlocks - Unix Makefiles" /home/sacha/CLionProjects/testProject
-- The C compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/gcc
CMake Error: Generator: execution of make failed. Make command was: /usr/bin/cmake cmTC_df723/fast &&
-- Check for working C compiler: /usr/bin/gcc -- broken
CMake Error at /usr/local/share/cmake-3.15/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"/usr/bin/gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/sacha/CLionProjects/testProject/cmake-build-release-system/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/cmake cmTC_df723/fast && No such file or directory
Generator: execution of make failed. Make command was: /usr/bin/cmake cmTC_df723/fast &&
Any help or directions appreciated, thanks!
The error message
CMake Error: Generator: execution of make failed.
signals, that something wrong with CMake settings or its generator.
In the given case you have additional message
Make command was: /usr/bin/cmake cmTC_df723/fast &&
which means that cmake is run as a Make command.
This is wrong: cmake and make commands are not interchangeable.
Would you inspect the very first command line, you will find the source of that problem:
-DCMAKE_MAKE_PROGRAM=/usr/bin/cmake
Exactly it sets cmake executable for Make command. You need to fix that line (e.g. in CLion settings).
I am trying to build a simple application on a Windows machine using CMake as the main build tool. Once CMake is invoked on the project the is an error on configuration phase:
> cmake -H. -G Ninja -Bbuild -DCMAKE_C_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe" -DCMAKE_CXX_COMPILER:PATH="C:\Program Files\LLVM\bin\clang-cl.exe"
-- The C compiler identification is Clang 7.0.0
-- The CXX compiler identification is Clang 7.0.0
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang-cl.exe --broken
CMake Error at C:/Program Files/CMake/share/cmake-3.12/Modules/CMakeTestCCompile
r.cmake:52 (message):
The C compiler
"C:/Program Files/LLVM/bin/clang-cl.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/mak/Desktop/cmake-test/build/CMakeFiles/CMakeTmp
Run Build Command:"C:/Qt/Tools/QtCreator/bin/ninja.exe" "cmTC_f5485"
[1/2] Building C object CMakeFiles\cmTC_f5485.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTC_f5485.exe
FAILED: cmTC_f5485.exe
cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_f5485.dir --manifests -- CMAKE_LINKER-NOTFOUND /nologo CMakeFiles\cmTC_f5485.dir\testCCompiler.c.obj /out:cmTC_f5485.exe /implib:cmTC_f5485.lib /pdb:cmTC_f5485.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 && cd ."
RC Pass 1: command "rc /foCMakeFiles\cmTC_f5485.dir/manifest.res CMakeFiles\cmTC_f5485.dir/manifest.rc" failed (exit code 0) with the following output:
The system cannot find the given file
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
I read a lot through the web but my problem was not solved by any proposed solution. What I found so far is a simmilar but maybe outdated solution to the same problem which did not work for me, because Ninja was not able to build the executable:
> ninja all
[1/2] Building CXX object CMakeFiles/minimal.dir/main.cpp.obj
FAILED: CMakeFiles/minimal.dir/main.cpp.obj
C:\PROGRA~1\LLVM\bin\clang-cl.exe -MD -MT CMakeFiles/minimal.dir/main.cpp.obj -MF CMakeFiles\minimal.dir\main.cpp.obj.d -o CMakeFiles/minimal.dir/main.cpp.obj -c ../main.cpp
clang-cl.exe: warning: unknown argument ignored in clang-cl: '-MF' [-Wunknown-argument]
clang-cl.exe: error: no such file or directory: 'CMakeFiles/minimal.dir/main.cpp.obj'
clang-cl.exe: error: no such file or directory: 'CMakeFiles\minimal.dir\main.cpp.obj.d'
ninja: build stopped: subcommand failed.
Before this error CMake configured properly except that all compilers ABI info detection failed - but CMake resumed without error. There are some other questions out there which did not help either.
The official documentation states it is quite simple but in fact it is not.
So: How do I build a simple C++ project using CMake with the Ninja generator and Clang as the compiler? I try to avoid the installation of Visual Studio but it would be great if generated binaries are compatible with MSVC build binaries.
Versions:
CMake 3.12.2
Ninja 1.8.2
Clang 7.0.0
Example: Here is the minial example which I am working with:
CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
project(minimal)
add_executable(${PROJECT_NAME} main.cpp)
main.cpp
#include <stdio.h>
int main(void)
{
printf("Hello World!\n");
return 0;
}
To compile with clang-cl, it is necessary to run cmake with MSVC environment loaded (use vcvarsall.bat). Otherwise it tries to use GCC compatibility options.
It is enough to install just the Build Tools.
I have been trying to get JetBrains CLion IDE working, but I am running into a problem with Cmake and none of my research online has been helpful. I installed cygwin with the necessary packages (as stated here - gcc/g++, cmake, make, gdb). When I open up CLion and go into Settings (I'm running Windows 10) under Build>Toolchains>Debugger everything has a check next to it, so it seems like CLion has found everything alright, but when I look in the Debugger window I get the following error:
"C:\Users\Lucas Lofaro\.CLion2016.3\system\cygwin_cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" "/cygdrive/c/Users/Lucas Lofaro/ClionProjects/cracking_the_coding_interview"
-- The CXX compiler identification is GNU 5.3.0
-- Check for working CXX compiler: /usr/bin/c++.exe
-- Check for working CXX compiler: /usr/bin/c++.exe -- broken
CMake Error at /cygdrive/c/Users/Lucas Lofaro/.CLion2016.3/system/cygwin_cmake/share/cmake-3.6.2/Modules/CMakeTestCXXCompiler.cmake:54 (message):
The C++ compiler "/usr/bin/c++.exe" is not able to compile a simple test
program.
It fails with the following output:
Change Dir: /cygdrive/c/Users/Lucas Lofaro/ClionProjects/cracking_the_coding_interview/cmake-build-debug/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make.exe" "cmTC_96921/fast"
/usr/bin/make -f CMakeFiles/cmTC_96921.dir/build.make
CMakeFiles/cmTC_96921.dir/build
make[1]: Entering directory '/cygdrive/c/Users/Lucas
Lofaro/ClionProjects/cracking_the_coding_interview/cmake-build-debug/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_96921.dir/testCXXCompiler.cxx.o
/usr/bin/c++.exe -o CMakeFiles/cmTC_96921.dir/testCXXCompiler.cxx.o -c
"/cygdrive/c/Users/Lucas
Lofaro/ClionProjects/cracking_the_coding_interview/cmake-build-debug/CMakeFiles/CMakeTmp/testCXXCompiler.cxx"
Linking CXX executable cmTC_96921.exe
"/cygdrive/c/Users/Lucas
Lofaro/.CLion2016.3/system/cygwin_cmake/bin/cmake.exe" -E cmake_link_script
CMakeFiles/cmTC_96921.dir/link.txt --verbose=1
/usr/bin/c++.exe -Wl,--enable-auto-import
CMakeFiles/cmTC_96921.dir/testCXXCompiler.cxx.o -o cmTC_96921.exe
-Wl,--out-implib,libcmTC_96921.dll.a
-Wl,--major-image-version,0,--minor-image-version,0
c++: fatal error: -fuse-linker-plugin, but cyglto_plugin.dll not found
compilation terminated.
CMakeFiles/cmTC_96921.dir/build.make:97: recipe for target 'cmTC_96921.exe'
failed
make[1]: *** [cmTC_96921.exe] Error 1
make[1]: Leaving directory '/cygdrive/c/Users/Lucas
Lofaro/ClionProjects/cracking_the_coding_interview/cmake-build-debug/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_96921/fast' failed
make: *** [cmTC_96921/fast] Error 2
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 "/cygdrive/c/Users/Lucas Lofaro/ClionProjects/cracking_the_coding_interview/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "/cygdrive/c/Users/Lucas Lofaro/ClionProjects/cracking_the_coding_interview/cmake-build-debug/CMakeFiles/CMakeError.log".
I've also added the cygwin bin directory to my Path environment variable, but I am really at a loss as to what to do next. Something isn't linking up and I don't want to start digging around in Cmake files without a better understanding of what's going on. Any guidance would be much appreciated. Please let me know if I can provide any additional information.
It turns out that the cmake, make, and g++ packages were installed but not updated to their most recent versions. Rerunning cygwin installer solved my problem and everything now compiles fine.
For a new project we want to use CMake. We are using Eclipse CDT as IDE and Cygwin gcc.
We generated the CMakeLists.txt and followed [this tutorial (option 2)][1].
When I try to run the described Make target to generate the Makefiles with CMake, which executes
cmake -E chdir C:/projects/eclipse_ws/MyApp/Build/ cmake -G "Unix Makefiles" ../ Run CMake
I get the error
CMake Error: The source directory "C:/projects/eclipse_ws/MyApp/Build/CMake" does not exist.
If I run the command directly from a Cygwin console it works just fine, however then I have to run make also from the Cygwin console, because the Makefiles are generated with Unix paths.
EDIT:
So I fixed this issue (see my answer below).
But I'm still having problems.
When I try to run CMake as Make target in Eclipse as suggested in the tutorial I get the following errors:
cmake -E chdir Build/ cmake -G 'Unix Makefiles' ../
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
System is unknown to cmake, create:
Platform/MINGW32_NT-6.1 to use this system, please send your config file to cmake#www.cmake.org so it can be added to cmake
Your CMakeCache.txt file was copied to CopyOfCMakeCache.txt. Please send that file to cmake#www.cmake.org.
-- Check for working C compiler: /usr/bin/gcc.exe
System is unknown to cmake, create:
Platform/MINGW32_NT-6.1 to use this system, please send your config file to cmake#www.cmake.org so it can be added to cmake
-- Check for working C compiler: /usr/bin/gcc.exe -- broken
CMake Error at /usr/share/cmake-2.8.9/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "/usr/bin/gcc.exe" is not able to compile a simple test
program.
It fails with the following output:
Change Dir: /cygdrive/c/projects/eclipse_ws/MyApp/Build/CMakeFiles CMakeTmp
Run Build Command:/usr/bin/make.exe "cmTryCompileExec726566634/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec726566634.dir/build.make
CMakeFiles/cmTryCompileExec726566634.dir/build
make[1]: Entering directory
'/cygdrive/c/projects/eclipse_ws/MyApp/Build/CMakeFiles/CMakeTmp'
/usr/bin/cmake.exe -E cmake_progress_report
/cygdrive/c/projects/eclipse_ws/MyApp/Build/CMakeFiles/CMakeTmp/CMakeFiles
1
Building C object
CMakeFiles/cmTryCompileExec726566634.dir/testCCompiler.c.obj
/usr/bin/gcc.exe -o
CMakeFiles/cmTryCompileExec726566634.dir/testCCompiler.c.obj -c
/cygdrive/c/projects/eclipse_ws/MyApp/Build/CMakeFiles/CMakeTmp/testCCompiler.c
CMakeFiles/cmTryCompileExec726566634.dir/build.make:60: recipe for target
'CMakeFiles/cmTryCompileExec726566634.dir/testCCompiler.c.obj' failed
make[1]: Leaving directory
'/cygdrive/c/projects/eclipse_ws/MyApp/Build/CMakeFiles/CMakeTmp'
make[1]: *** [CMakeFiles/cmTryCompileExec726566634.dir/testCCompiler.c.obj]
Error 1
Makefile:117: recipe for target 'cmTryCompileExec726566634/fast' failed
make: *** [cmTryCompileExec726566634/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred!
Seems like for some reason CMake assumes I have an MinGW environment and not Cygwin.
EDIT2
MinGW system was assumed, because a Git installation was in PATH before Cygwin and Git's uname command was used (which returns MinGW).
If you check "Make Target - Same as the target name" in Eclipse's Make dialog, Eclipse will add a
Run CMake
to the command (see question), which is misinterpreted by CMake.
I just unchecked "Same as the target name".