CMake, the c compiler unable to compile simple test program - c++

I'm trying to compile my project using cmake with mingw but getting error:
cmake -G "MinGW Makefiles" ../
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: D:/mingw/bin/gcc.exe
-- Check for working C compiler: D:/mingw/bin/gcc.exe -- broken
CMake Error at C:/Program Files/CMake/share/cmake-3.9/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "D:/mingw/bin/gcc.exe" is not able to compile a simple test
program.
Where is the problem?

Sometimes there are problems if the directory has any spaces in it's name, like yours has in "Program files". Try to copy the sdk to another location without spaces and see what happens

Related

Cmake automatically defaults to gcc-5

I was trying to compile amber tools using cmake. I am using ubuntu Ubuntu 16.04.7 LTS with the default gcc version gcc-5 and g++5, and amber tool requires at least gcc-6. I have installed gcc-8 and g++8 and specified it using the CMAKE_C_COMPILER and CMAKE_CXX_COMPILER. The cmake command used is the command below:
cmake $AMBER_PREFIX/amber22_src \
-DCMAKE_INSTALL_PREFIX=$AMBER_PREFIX/amber22 \
-DCOMPILER=GNU \
-DMPI=FALSE -DCUDA=TRUE -DINSTALL_TESTS=TRUE \
-DDOWNLOAD_MINICONDA=TRUE \
-DCMAKE_C_COMPILER=/usr/bin/gcc-8 -DCMAKE_CXX_COMPILER=/usr/bin/g++-8 \
Even though the gcc g++ is specified I get the following error:
-- Starting configuration of Amber version 22.0.0...
-- CMake Version: 3.14.0
-- For how to use this build system, please read this wiki:
-- http://ambermd.org/pmwiki/pmwiki.php/Main/CMake
-- For a list of important CMake variables, check here:
-- http://ambermd.org/pmwiki/pmwiki.php/Main/CMake-Common-Options
-- **************************************************************************
-- Setting C compiler to gcc
-- Setting CXX compiler to g++
-- Setting Fortran compiler to gfortran
-- Amber source not found, only building AmberTools
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- The Fortran compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working Fortran compiler: /usr/bin/gfortran
-- Check for working Fortran compiler: /usr/bin/gfortran -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /usr/bin/gfortran supports Fortran 90
-- Checking whether /usr/bin/gfortran supports Fortran 90 -- yes
--
************************************************************
Error: Amber requires at least g++-6.0
See https://ambermd.org/Installation.php for more info
************************************************************
--
CMake Error at cmake/VerifyCompilerConfig.cmake:30 (message):
Call Stack (most recent call first):
cmake/AmberBuildSystem2ndInit.cmake:30 (include)
CMakeLists.txt:111 (include)
-- Configuring incomplete, errors occurred!
See also "/media/gpu-1/GPU_1_2TB/Ambertools22/amber22_src/build/CMakeFiles/CMakeOutput.log".
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= /usr/bin/gcc-8
CMAKE_CXX_COMPILER= /usr/bin/g++-8
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
DOWNLOAD_MINICONDA
MPI
-- Build files have been written to: /media/gpu-1/GPU_1_2TB/Ambertools22/amber22_src/build
If the cmake build report looks OK, you should now do the following:
make install
source /media/gpu-1/GPU_1_2TB/Ambertools22/amber22/amber.sh
Thank you
I would not call it a problem of CMake, rather on the way Amber performs the control of the compiler through CMake, which most likely is performed by taking the first compiler that appears from the environment variable $PATH.
If you would like to compile it anyway, I can suggest two cheap ways:
using the update-alternatives package, to change the "system
default" gcc and g++
prepend a path in PATH with export PATH=absolute/path/to/a/folder:$PATH, and in this path put two symbolic links called gcc and g++, that points at
gcc-8 and g++-8
According to this, you are still using existing cache files that you've generated before you set the new C and CXX compiler.
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_C_COMPILER= /usr/bin/gcc-8
CMAKE_CXX_COMPILER= /usr/bin/g++-8
Based on cmake $AMBER_PREFIX/amber22_src you are running this from your build folder. In general I recommend using the syntax cmake -S[source] -B[build]. Your current working directory should be completely deleted. Once you do that, re-run your cmake command and it should be correctly set.
If it doesn't work you can do a sanity check by adding
set(CMAKE_C_COMPILER [path_to_C])
set(CMAKE_CXX_COMPILER [path_to_CXX])
BE SURE TO PUT IT AT THE START OF THE CMAKELISTS FILE i.e. before any project() line.
EDIT: Also have you heard about docker? It's a great tool for creating special contained environments for using legacy tools.

The C compiler "/usr/bin/cc" is not able to compile a simple test program on cygwin

I found some other topic has the same problem but it seems the solution for me
I'm trying to install FC4SC library (https://github.com/amiq-consulting/fc4sc)
And this is tested by google test. when I do following the guideline
I used the command:
cmake -DBUILD_GTEST=ON BUILD_GTEST -DBUILD_SHARED_LIBS=ON ..
And then it showed like this
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- broken
CMake Error at /usr/share/cmake-3.14.5/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"/usr/bin/cc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /cygdrive/d/SystemC/7_UVM/Coverage/fc4sc-master/test/googletest/build/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make.exe cmTC_7a5cd/fast
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:4 (project)
-- Configuring incomplete, errors occurred!
See also "/cygdrive/d/SystemC/7_UVM/Coverage/fc4sc-master/test/googletest/build/CMakeFiles/CMakeOutput.log".
See also "/cygdrive/d/SystemC/7_UVM/Coverage/fc4sc-master/test/googletest/build/CMakeFiles/CMakeError.log".
I tried to reinstall gcc and some other component that they are related but It didn't work
Following is the cmake Error output:

Can't get CMAKE to compile a project

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

CMake passes Visual C++ parameters to clang instead of expexted GCC ones

I'm trying to build the project under win10 using mingw latest toolchain and clang compilers (from CLion IDE) with explicitly specified compilers in commandline options :
-DCMAKE_C_COMPILER=C:/dev/tools/LLVM/bin/clang.exe
-DCMAKE_CXX_COMPILER=C:/dev/tools/LLVM/bin/clang++.exe
cmake recognize clang correctly, but during the test compilations tries to pass cl (Visual C++ compiler) flags:
C:\dev\tools\CLion.RC\bin\cmake\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=C:/dev/tools/LLVM/bin/clang.exe -DCMAKE_CXX_COMPILER=C:/dev/tools/LLVM/bin/clang++.exe -G "CodeBlocks - MinGW Makefiles" C:\Users\amigo421\ClionProjects\hr2
-- The C compiler identification is unknown
-- The CXX compiler identification is Clang 3.9.0
-- Check for working C compiler: C:/dev/tools/LLVM/bin/clang.exe
-- Check for working C compiler: C:/dev/tools/LLVM/bin/clang.exe -- broken CMake Error at
C:/dev/tools/CLion.RC/bin/cmake/share/cmake-3.6/Modules/CMakeTestCCompiler.cmake:61
(message): The C compiler "C:/dev/tools/LLVM/bin/clang.exe" is not
able to compile a simple test program.
It fails with the following output:
C:\dev\tools\LLVM\bin\clang.exe /DWIN32 /D_WINDOWS /W3 -o
CMakeFiles\cmTC_397ea.dir\testCCompiler.c.obj -c
C:\Users\amigo421\ClionProjects\hr2\cmake-build-debug\CMakeFiles\CMakeTmp\testCCompiler.c
**clang.exe: error: no such file or directory: '/DWIN32'**
**clang.exe: error: no such file or directory: '/D_WINDOWS'**
**clang.exe: error: no such file or directory: '/W3'**
CMakeFiles\cmTC_397ea.dir\build.make:64: recipe for target
'CMakeFiles/cmTC_397ea.dir/testCCompiler.c.obj' failed
mingw32-make.exe[1]: ***
[CMakeFiles/cmTC_397ea.dir/testCCompiler.c.obj] Error 1
mingw32-make.exe[1]: Leaving directory
'C:/Users/amigo421/ClionProjects/hr2/cmake-build-debug/CMakeFiles/CMakeTmp'
you see that cmake passes visual c++ flags , I don't plan to use clang-cl.
I suppose that cmake should use GCC (MinGW) parameters in command line
any idea how to fix this

Error on compile qml-material on windows

How to compile and install the qml-material on windows7 machine ?
First of all I clone and compile extra-cmake-modules like below:
git clone git://anongit.kde.org/extra-cmake-modules
cd extra-cmake-modules
mkdir build
cd build
cmake -G "MinGW Makefiles" ..
After that I run the Make command but with no output!(No error and no change!)
And for compile the qml-material I use the below instruction:
mkdir build
cd build
cmake -G "MinGW Makefiles" ..
But I get error:
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: C:/bin/cxx/Qt/Qt5.5.1/Tools/mingw492_32/bin/gcc.exe
-- Check for working C compiler: C:/bin/cxx/Qt/Qt5.5.1/Tools/mingw492_32/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/bin/cxx/Qt/Qt5.5.1/Tools/mingw492_32/bin/g++.exe
-- Check for working CXX compiler: C:/bin/cxx/Qt/Qt5.5.1/Tools/mingw492_32/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at C:/Users/me/Documents/Github/ecm/ECMConfig.cmake:35 (include):
include could not find load file:
C:/Users/me/share/ECM/modules//ECMUseFindModules.cmake
Call Stack (most recent call first):
CMakeLists.txt:13 (find_package)
CMake Error at CMakeLists.txt:16 (include):
include could not find load file:
KDEInstallDirs
CMake Error at CMakeLists.txt:17 (include):
include could not find load file:
KDECMakeSettings
CMake Error at CMakeLists.txt:18 (include):
include could not find load file:
KDECompilerSettings
CMake Error at tests/CMakeLists.txt:1 (include):
include could not find load file:
ECMMarkAsTest
CMake Error at tests/CMakeLists.txt:13 (ecm_mark_as_test):
Unknown CMake command "ecm_mark_as_test".
-- Configuring incomplete, errors occurred!
I was try to use QtCreator to compile ECM and also the after that the qml-material, ECM compile and build fine without any error but the qml-material show above error too!!!
thanks,
I will provide my comment as an answer for a better overview:
To use qml-material it is not really necessary to "build" the project with cmake because the project itself contains only plain qml files.
I do not know why the guys switched from qmake to cmake system.
However all you need to do is to simply copy the file structure to your local file system:
checkout the project with git clone https://github.com/papyros/qml-material.git
copy the content of qml-material/modules/Material to Qt5.5.1/5.5/mingw/qml/Material and qml-material/modules/QtQuick/Controls/Styles/Material to Qt5.5.1/5.5/mingw/qml/QtQuick/Controls/Styles/Material where mingw stands for your Qt platform. Could also be gcc4.9 or something like this.
That`s all.