cmake uses wrong version of compiler - cmake

I work with cmake and ninja in Windows 7. It worked flawless, till i opend an older version of my IDE. Now cmake uses the wrong compiler. Instead of
C:/Program Files (x86)/Embarcadero/Studio/19.0/bin/bcc32x.exe it now tries to use C:/Program Files (x86)/Embarcadero/RAD Studio/9.0/bin/bcc32x.exe.
Of course I read similar Questions here on stackoverflow and tried the solutions described there, but nothing seems to work (How do you set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER for building Assimp for iOS? for example). Even reinstallation of cmake does nothing. My windows environment variables are ok.
When i try to set CMake variables at command line like this:
cmake -G Ninja -D CMAKE_C_COMPILER="C:\\Program Files
(x86)\\Embarcadero\\Studio\\19.0\\bin\\bcc32x.exe" -D
CMAKE_CXX_COMPILER="C:\\Program Files (x86)\\Embarcadero\\Studio\\19.0
\\bin\\bcc32x.exe"
cmd Output was
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Alle Rechte vorbehalten.
C:\Users\cld>cd c:\
c:\>cmake -G Ninja -D CMAKE_C_COMPILER="C:\\Program Files
(x86)\\Embarcadero\\Studio\\19.0\\bin\\bcc32x.exe" -D
CMAKE_CXX_COMPILER="C:\\Program Files (x86)\\Embarcadero\\Studio\\19.0
\\bin\\bcc32x.exe"
C:\Users\cld\Desktop\smallCmakeTest
-- The C compiler identification is Embarcadero 7.30.36015
-- The CXX compiler identification is Embarcadero 7.30.36015
-- Check for working C compiler: C:/Program Files (x86)/Embarcadero/RAD
Studio/9.0/bin/bcc32x.exe
-- Check for working C compiler: C:/Program Files (x86)/Embarcadero/RAD
Studio/9.0/bin/bcc32x.exe -- broken
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.10/Modules
/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"C:/Program Files (x86)/Embarcadero/RAD Studio/9.0/bin/bcc32x.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/cld/Desktop/smallCmakeTest/CMakeFiles/CMakeTmp
Run Build Command:"C:/ninja/ninja.exe" "cmTC_c1b2f"
[1/2] Building C object CMakeFiles\cmTC_c1b2f.dir\testCCompiler.c.obj
FAILED: CMakeFiles/cmTC_c1b2f.dir/testCCompiler.c.obj
"C:\Program Files (x86)\Embarcadero\RAD Studio\9.0\bin\bcc32x.exe"
-I"C:\Program Files (x86)\Embarcadero\RAD Studio\9.0\include\windows\crtl"
-I"C:\Program Files (x86)\Embarcadero\RAD Studio\9.0\
include\windows\sdk" -I"C:\Program Files (x86)\Embarcadero\RAD Studio\9.0
\include\windows\rtl" -I"C:\Program Files (x86)\Embarcadero\RAD Studio\9.0
\include\dinkumware64" -tM -O0 -v -oCMakeFiles\cmTC_
c1b2f.dir\testCCompiler.c.obj -c testCCompiler.c
CreateProcess failed: The system cannot find the file specified.
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:1 (project)
CMake Error at CMakeLists.txt:1 (project):
The CMAKE_CXX_COMPILER:
C:/Program Files (x86)/Embarcadero/RAD Studio/9.0/bin/bcc32x.exe
is not a full path to an existing compiler tool.
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.
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 3.10)
should be added at the top of the file. The version specified may be
lower
if you wish to support older CMake versions for this project. For
more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring incomplete, errors occurred!
See also "C:/Users/cld/Desktop/smallCmakeTest/CMakeFiles
/CMakeOutput.log".
See also "C:/Users/cld/Desktop/smallCmakeTest/CMakeFiles
/CMakeError.log".

Related

Create Portable CMake/MingGW(G++) [duplicate]

I have a problem with this CMakeLists.txt file:
cmake_minimum_required(VERSION 2.6)
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
SET(CMAKE_CXX_COMPILER C:/MinGW/bin/g++)
project(cmake_test)
add_executable(a.exe test.cpp)
Calling cmake with: cmake -G "MinGW Makefiles" , it fails with the following output:
c:\Users\pietro.mele\projects\tests\buildSystem_test\cmake_test>cmake -G "MinGW Makefiles" .
-- The C compiler identification is GNU 4.6.1
-- The CXX compiler identification is GNU 4.6.1
-- Check for working C compiler: C:/MinGW/bin/gcc
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Check for working C compiler: C:/MinGW/bin/gcc -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "C:/MinGW/bin/gcc" is not able to compile a simple test
program.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:10 (project)
CMake Error: your C compiler: "C:/MinGW/bin/gcc" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "C:/MinGW/bin/g++" was not found. Please set CMAKE_CXX_COMPILER to a valid compiler path or name.
-- Configuring incomplete, errors occurred!
However the gcc compiler is in C:/MinGW/bin/ and it works.
Any idea?
Platform:
Windows 7
MinGW/GCC 4.6
Never try to set the compiler in the CMakeLists.txt file.
See the CMake FAQ about how to use a different compiler:
https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-do-i-use-a-different-compiler
(Note that you are attempting method #3 and the FAQ says "(avoid)"...)
We recommend avoiding the "in the CMakeLists" technique because there are problems with it when a different compiler was used for a first configure, and then the CMakeLists file changes to try setting a different compiler... And because the intent of a CMakeLists file should be to work with multiple compilers, according to the preference of the developer running CMake.
The best method is to set the environment variables CC and CXX before calling CMake for the very first time in a build tree.
After CMake detects what compilers to use, it saves them in the CMakeCache.txt file so that it can still generate proper build systems even if those variables disappear from the environment...
If you ever need to change compilers, you need to start with a fresh build tree.
I had similar problem as Pietro,
I am on Window 10 and using "Git Bash".
I tried to execute >>cmake -G "MinGW Makefiles", but I got the same error as Pietro.
Then, I tried >>cmake -G "MSYS Makefiles", but realized that I need to set my environment correctly.
Make sure set a path to C:\MinGW\msys\1.0\bin and check if you have gcc.exe there. If gcc.exe is not there then you have to run C:/MinGW/bin/mingw-get.exe and install gcc from MSYS.
After that it works fine for me
Using with FILEPATH option might work:
set(CMAKE_CXX_COMPILER:FILEPATH C:/MinGW/bin/gcc.exe)
I had the same issue. And in my case the fix was pretty simple. The trick is to simply add the ".exe" to your compilers path. So, instead of :
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc)
It should be
SET(CMAKE_C_COMPILER C:/MinGW/bin/gcc.exe)
The same applies for g++.

Using CMake with Eclipse CDT and Cygwin on Windows

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".

CGAL cmake on cygwin fails

I'm trying to compile CGAL 4.5 on cygwin (windows 7). i have gcc-core, gcc-g++ and gmp installed but when i try to run cmake i get following error:
$ cmake .
-- The CXX compiler identification is GNU 4.8.3
CMake Error: Could not find cmake module file:/home/metalab/CGAL-4.5/CMakeFiles/2.8.11.2/CMakeCXXCompiler.cmake
-- The C compiler identification is GNU 4.8.3
CMake Error: Could not find cmake module file:/home/metalab/CGAL-4.5/CMakeFiles/2.8.11.2/CMakeCCompiler.cmake
CMake Warning at /usr/share/cmake-2.8.11.2/Modules/Platform/CYGWIN.cmake:15 (message):
CMake no longer defines WIN32 on Cygwin!
(1) If you are just trying to build this project, ignore this warning or
quiet it by setting CMAKE_LEGACY_CYGWIN_WIN32=0 in your environment or in
the CMake cache. If later configuration or build errors occur then this
project may have been written under the assumption that Cygwin is WIN32.
In that case, set CMAKE_LEGACY_CYGWIN_WIN32=1 instead.
(2) If you are developing this project, add the line
set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required
at the top of your top-level CMakeLists.txt file or set the minimum
required version of CMake to 2.8.4 or higher. Then teach your project to
build on Cygwin without WIN32.
Call Stack (most recent call first):
/usr/share/cmake-2.8.11.2/Modules/CMakeSystemSpecificInformation.cmake:36 (include)
CMakeLists.txt:7 (project)
CMake Error: Could not find cmake module file:/home/metalab/CGAL-4.5/CMakeFiles/2.8.11.2/CMakeRCCompiler.cmake
-- Check for working CXX compiler: /usr/bin/c++.exe
CMake Error at /usr/share/cmake-2.8.11.2/Modules/CMakeTestCXXCompiler.cmake:40 (try_compile):
Unknown extension ".cxx" for file
/home/metalab/CGAL-4.5/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
try_compile() works only for enabled languages. Currently these are:
C CXX RC
See project() command to enable other languages.
Call Stack (most recent call first):
CMakeLists.txt:7 (project)
-- Check for working CXX compiler: /usr/bin/c++.exe -- broken
CMake Error at /usr/share/cmake-2.8.11.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:
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:7 (project)
-- Configuring incomplete, errors occurred!
i already tried playing with CMAKE_LEGACY_CYGWIN_WIN32 but no success.
I ran in a similar error. cmake seemed to not be able to find anything from Cygwin.
The fact is that you need to run the Cygwin version of cmake. If you installed cmake from an installer and it went under C:\Program Files, you have the wrong cmake and it won't find most everything which it should otherwise find.

CMake error: For MinGW make to work correctly sh.exe must NOT be in your path

I am trying to built a "Hello World" project with Qt 5 and cmake under MinGW.
This is the CMakeLists.txt file (taken from the on-line doc):
project(Qt5_cmake_test)
cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.1.1/5.1.1/mingw48_32")
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Find the QtWidgets library
find_package(Qt5Widgets)
# Add the source files from the current directory
aux_source_directory(. SRC_LIST)
# Tell CMake to create the executable
add_executable(${PROJECT_NAME} WIN32 ${SRC_LIST})
# Use the Widgets module from Qt5
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
The source code is the one generated automatically when creating a new project (which produces an empty window).
Configuring from the Windows command prompt with: cmake -G "MinGW Makefiles" ..\Qt5_cmake_test
I get these errors:
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeMinGWFindMake.cmake:20 (message):
sh.exe was found in your PATH, here:
C:/Program Files (x86)/Git/bin/sh.exe
For MinGW make to work correctly sh.exe must NOT be in your path.
Run cmake from a shell that does not have sh.exe in your PATH.
If you want to use a UNIX shell, then use MSYS Makefiles.
Call Stack (most recent call first):
CMakeLists.txt:8 (project)
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file:C:/Users/pietro.mele/projects/tests/buildSystem_test/Qt5_cmake_test-build/CMakeFiles/2.8.11.2/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file:C:/Users/pietro.mele/projects/tests/buildSystem_test/Qt5_cmake_test-build/CMakeFiles/2.8.11.2/CMakeCXXCompiler.cma
ke
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
So it seems it is not able to find the compiler. Is there a way to let cmake find it on its own, or just giving it the CMAKE_PREFIX_PATH directory?
Do I have to manually specify all those variables in the makefile or as environment variables in Windows?
I tried both from the standard Windows command prompt and from the one provided by Qt, with the same result. Is it OK to build from the Windows command prompt, or should I do it from the MinGW's shell?
Platform:
Qt 5.1
CMake 2.8.11.2
MinGW/GCC 4.8
Windows 7
Get the git path out of your PATH before running cmake.
Here is the magic to do that:
set PATH=%PATH:C:/Program Files (x86)/Git/bin;=%
This CMakeLists.txt file works properly:
project(Qt5_cmake_test)
cmake_minimum_required(VERSION 2.8.11)
set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.1.1/5.1.1/mingw48_32")
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Find the Qt libraries
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
# Add the source files from the current directory
aux_source_directory(. SRC_LIST)
# Tell CMake to create the executable
add_executable(${PROJECT_NAME} WIN32 ${SRC_LIST})
# Use Qt5 modules
target_link_libraries(${PROJECT_NAME}
Qt5::Widgets
Qt5::WinMain)
The changes are:
Added find_package(Qt5Core REQUIRED).
Added Qt5::WinMain to target_link_libraries.
In some of my answer here on SO, I have described. CMake does not like sh.exe.
sh.exe was found in your PATH, here:
C:/Program Files (x86)/Git/bin/sh.exe
Solution : Rename C:/Program Files (x86)/Git/bin/sh.exe shortly.
For example:
C:/Program Files (x86)/Git/bin/shxx.exe
But do not forget when everything is built. rename properly again.

CMake cannot compile test program as source directory doesnt exist

all. I'm trying to use cmake for compile some android code with android toolchain on Windows 7x64.
when i call cmake as following
cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=android.cmake 1>!cmake.log 2>!cmake.error.log
I run this command from Administrator console and get following output:
!cmake.log
-- The C compiler identification is GNU 4.6.0
-- The CXX compiler identification is GNU 4.6.0
-- Check for working C compiler: c:/cygwin/usr/local/android-toolchain-r8ea9/bin/arm-linux-androideabi-gcc.exe
-- Check for working C compiler: c:/cygwin/usr/local/android-toolchain-r8ea9/bin/arm-linux-androideabi-gcc.exe -- broken
-- Configuring incomplete, errors occurred!
!cmake.error.log
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler
"c:/cygwin/usr/local/android-toolchain-r8ea9/bin/arm-linux-androideabi-gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/PDK_BUILD/openssl/CMakeFiles/CMakeTmp
Run Build Command:C:/PROGRA~2/CMAKE2~1.8/bin/cmake.exe
"cmTryCompileExec333575975/fast"
CMake Error: The source directory
"C:/PDK_BUILD/openssl/CMakeFiles/CMakeTmp/cmTryCompileExec333575975/fast"
does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
I granted adninistrator rights for cmake.exe itself, cleared read-only attributes from CMakeFiles folder and disabled anti-virus but still not worked.
It looks like you are running into CMake Bug 0013131. This comment suggests that using unset TMP should fix the problem. Don't forget to delete the CMakeCache.txt and CMakeFiles folders (or the entire build tree when using out-of-source builds), before retrying.