CMAKE_CXX_COMPILER not set in qtcreator - cmake

Is there a way (like command line argument or some function in CMakeLists.txt) to print all command line arguments supplied to cmake invocation? Equivalent of bash "echo $#"
I need this to debug, why cmake invoked from qtcreator does not find my compiler (msvc12). After inspecting qtcreator sources, I see that it appends some environment by cmake arguments depending on selected kit. I got messages like
CMAKE_CXX_COMPILER not set
, when I select both "Nmake Desktop Qt MSVC2013 ..." or "Ninja Qt MSVC2013".
When I call cmake from command line, it finds compiler with no additional parameters:
-- Check for working CXX compiler using: Visual Studio 12 2013
-- Check for working CXX compiler using: Visual Studio 12 2013 -- works

My main problem was solved by installing ninja. I thought that the problem was not finding compiler by cmake invoked by qtcreator:
CMAKE_CXX_COMPILER not set
After installing ninja and restarting qtcreator, the problem was gone.

I had the same problem after upgrading Visual Studio 2017.
For some reason, when ADDING (?) CMAKE_CXX_COMPILER in the cmake configuration in Build & Run to the location of the Visual Studio compiler, it should work:
Key: CMAKE_CXX_COMPILER
Value: C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe ==> replace version with the correct one
Don't forget to click "Apply Configuration Changes" below.
Very strange though, because after building, the cmake run becomes CMake Project was parsed successfully.and believe-it-or-not, the CMAKE_CXX_COMPILER is gone!

Related

Cannot install Theano libgpuarray on Windows 10

This question is for Python2.7 with Keras as a front end. I have Microsoft Visual Studio 2017 and I believe I have all the tools it needs. I followed the instructions on install CUDA. I believe it is version 10, and I think it is installed correctly. I followed the tutorial video and got a similar result at the end for the sample test. I have now moved on to installing libgpuarray. I have completed the following steps and got this error:
C:\Windows\system32>cd C:\Users\Never\Downloads\libgpuarray
C:\Users\Never\Downloads\libgpuarray>cd Build
C:\Users\Never\Downloads\libgpuarray\Build>cmake .. -DCMAKE_BUILD_TYPE=Release
-- Building for: Visual Studio 15 2017
-- The C compiler identification is MSVC 19.16.27034.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
CMake Deprecation Warning at CMakeLists.txt:26 (cmake_policy):
The OLD behavior for policy CMP0063 will be removed from a future version
of CMake.
The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
-- Looking for strlcat
-- Looking for strlcat - not found
-- Looking for mkstemp
-- Looking for mkstemp - not found
-- Found PkgConfig: C:/MinGW_w64/bin/pkg-config.exe (found version "0.25")
-- Checking for one of the modules 'check'
Tests disabled because Check was not found
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_BUILD_TYPE
-- Build files have been written to: C:/Users/Never/Downloads/libgpuarray/Build
I tried running C:\Users\Never\Downloads\libgpuarray\Build>make next but it returned:
'make' is not recognized as an internal or external command,operable program or batch file.
There is a make script in the folder above so I tried using it, with this result:
C:\Users\Never\Downloads\libgpuarray\Build>C:\Users\Never\Downloads\libgpuarray\make.bat
C:\Users\Never\Downloads\libgpuarray\Build>REM This helps repetitive builds on windows
C:\Users\Never\Downloads\libgpuarray\Build>REM It needs the compiler you want to use to be available in the shell
C:\Users\Never\Downloads\libgpuarray\Build>REM and it will build a release version
C:\Users\Never\Downloads\libgpuarray\Build>del bld
Could Not Find C:\Users\Never\Downloads\libgpuarray\Build\bld
C:\Users\Never\Downloads\libgpuarray\Build>mkdir bld
C:\Users\Never\Downloads\libgpuarray\Build>cd bld
C:\Users\Never\Downloads\libgpuarray\Build\bld>cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release
CMake Error: Error: generator : NMake Makefiles
Does not match the generator used previously: Visual Studio 15 2017
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.
C:\Users\Never\Downloads\libgpuarray\Build\bld>cmake --build . --config Release
Error: could not load cache
C:\Users\Never\Downloads\libgpuarray\Build\bld>cd ..
I am not 100% sure what to do next. I don't want to tinker and break things further, any assistance would be appreciated, thank you.
It looks like you are following the Linux instructions in the tutorial you linked. You should probably take a look at the Windows-specific instructions, considering you are building on Windows with Visual Studio.
It sounds like you may have corrupted your CMake cache a bit by running the make.bat file, so it's probably best to delete your Build folder and start over:
C:\Users\Never\Downloads\libgpuarray>mkdir Build && cd Build
C:\Users\Never\Downloads\libgpuarray\Build>cmake ..
From there, just follow the Windows-specific guidelines from the tutorial:
It will generate a Visual Studio solution file for the version installed. To build the project open this file (.sln) and run the “Build All” command after selecting the appropriate build type.

CMake generation problem with Visual Studio 2017

Using cmake from command line, I got:
"== Building Windows-Release =="
-- Building for: Visual Studio 15 2017
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:2 (project):
No CMAKE_C_COMPILER could be found.
CMake Error at CMakeLists.txt:2 (project):
No CMAKE_CXX_COMPILER could be found.
Where CMakeError.log contain:
Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler:
Build flags:
Id flags:
The output was:
1
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 31/12/2018 12:54:05.
Project "C:\myproj\CMakeFiles\3.13.1\CompilerIdC\CompilerIdC.vcxproj" on node 1 (default targets).
PrepareForBuild:
Creating directory "Debug\".
Creating directory "Debug\CompilerIdC.tlog\".
InitializeBuildStatus:
Creating "Debug\CompilerIdC.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe /c /nologo /W0 /WX- /Od /Oy- /D _MBCS /Gm- /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"Debug\\" /Fd"Debug\vc140.pdb" /Gd /TC /analyze- /errorReport:queue CMakeCCompilerId.c
CMakeCCompilerId.c
c1 : fatal error C1083: Cannot open source file: 'CMakeCCompilerId.c': No such file or directory [C:\myproj\CMakeFiles\3.13.1\CompilerIdC\CompilerIdC.vcxproj]
Done Building Project "C:\myproj\CMakeFiles\3.13.1\CompilerIdC\CompilerIdC.vcxproj" (default targets) -- FAILED.
Build FAILED.
"C:\myproj\CMakeFiles\3.13.1\CompilerIdC\CompilerIdC.vcxproj" (default target) (1) ->
(ClCompile target) ->
c1 : fatal error C1083: Cannot open source file: 'CMakeCCompilerId.c': No such file or directory [C:\myproj\CMakeFiles\3.13.1\CompilerIdC\CompilerIdC.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.43
...
I tried repairing the installation of Visual Studio, and renstalling CMake, but nothing seems to work it. Also looked at similar thread here, but nothing was helpful.
I met the exact same question with you. After a very very long struggle, I finally find the solution for me. I am not sure whether that is the same problem you met, but I still want to write and recode this strange problem.
Firstly, I also reinstall cmake, repair the VS and add many components in it and fixed(brake) many PATH environments, but all of them don't work, and I bet the problem is not because of these problems.
As the two messages:
The C compiler identification is unknown
The CXX compiler identification is unknown
They do not exactly mean the cmake don't detect the VS compiler, it just means that the cmake's use it to build its demo but fail. And from the errorlog, I even can believe your VS has already installed success and work well. The only problem is that the compiler can't open the 'CMakeCCompilerId.c' file.
I don't know whether have your check the .c file is exactly in the project location, but it is in there very well in my computer (otherwise, it means that the cmake failed to create this file, and maybe you need to open it as an administration)
I am very confused about why the compiler can't read that and try to directly open the .vcxproj file in VS and change many settings but still get the same error, like below.
After some try, I move the project to the desktop and reopen it, then it builds success! So as the whole cmake project. I am also be shocked by that.
After some compare and research, I found error reason in me, I am using the git in windows-wsl to clone the project to my windows file system(it has a little risk to break the file permission in wsl), it works well in normal, but as a cmake cross-compilation, I guess it may use some linux-like way to operate files and therefore meet some file permission problem.
So, the final solution to me is using the git in cmd or download the whole project in the browser instead of using the git in wsl. (Truly a little funny-. and may differ with your situation)
Hope these can help you.
The reason for my problem turned out to be that case sensitivity was turned on in the current directory.
Turn off case sensitivity or switch to another directory.

CMake does not support toolset specification

I'm trying to build the Checked-C project which uses CMake, but when I go to generate the makefile CMake gives the following error.
~/checkedc/build$ cmake ../llvm
CMake Error at CMakeLists.txt:57 (project):
Generator
Unix Makefiles
does not support toolset specification, but toolset
host=x64
was specified.
-- Configuring incomplete, errors occurred!
I have CMake version 3.9.1 installed along with GNU Make 4.1, Clang 5, and GCC 7. Anyone able to tell me what this CMake error means?
That section of CMakeLists.txt looks like this:
57 project(LLVM
58 ${cmake_3_0_PROJ_VERSION}
59 ${cmake_3_0_LANGUAGES}
60 C CXX ASM)
I've tried setting C/CXX/ASM but get the same error:
~/checkedc/build$ cmake -DCMAKE_C_COMPILER="clang-5.0" -DCMAKE_CXX_COMPILER="clang-5.0" -DCMAKE_ASM_COMPILER="clang-5.0" ../llvm
CMake Error at CMakeLists.txt:57 (project):
Generator
Unix Makefiles
does not support toolset specification, but toolset
host=x64
was specified.
-- Configuring incomplete, errors occurred!
I'm on Kubuntu 17.10 64bit.
It means that somewhere CMake file the variable CMAKE_GENERATOR_TOOLSET is set to host=x64. This only makes sense for Visual Studio generator so CMake opts to throw an error in this case.
To fix it double check the setup for your OS and generator. If this doesn't help then you'll need to find where this variable is set and remove this line.
I have the same issue - how I fixed it in my case. Indeed, I had copied the setup for cmake from windows then ported to Linux. When you run the first time, it will create in the build directory a file called: CMakeCache.txt. This file keeps some variables set initially for Windows. I removed it, together with all the CMakeFiles directory and rerun the cmake command to generate the project. It was working perfectly, but I had to set the CMAKE_CXX_COMPILER and CMAKE_C_COMPILER variables to the cmake command: -DCMAKE_CXX_COMPILER=/usr/bin/g++ -DCMAKE_C_COMPILER=/usr/bin/gcc
Hope it is working for you too.

CMake Error : execution of make failed on Windows

I am getting errors when trying to build nanomsg project in Windows 7:
cmake ..
-- Building for: NMake Makefiles
-- The C compiler identification is GNU 4.7.1
-- Check for working C compiler: C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: "nmake" "/NOLOGO" "cmTC_5d837\fast"
-- Check for working C compiler: C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe -- broken
CMake Error at C:/Program Files (x86)/cmake-3.9.4-win64-x64/share/cmake-3.9/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe" is not
able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/User/Documents/Internal/nanomsg-master/build/CMakeFiles/CMakeTmp
Run Build Command:"nmake" "/NOLOGO" "cmTC_5d837\fast"
Generator: execution of make failed. Make command was: "nmake" "/NOLOGO"
"cmTC_5d837\fast"
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:29 (project)
-- Configuring incomplete, errors occurred!
See also "C:/Users/User/Documents/Internal/nanomsg-master/build/CMakeFiles/CMakeOutput.log".
See also "C:/Users/User/Documents/Internal/nanomsg-master/build/CMakeFiles/CMakeError.log".
I use gcc compiler and make from Mingw toolchain and I can run succesfully gcc.exe and mingw32-make.exe on a simple example.
In the file CMakeCache.txt the cache variables are set as follows:
//C compiler
CMAKE_C_COMPILER:FILEPATH=C:/Program Files (x86)/CodeBlocks/MinGW/bin/gcc.exe
//Program used to build from makefiles.
CMAKE_MAKE_PROGRAM:STRING=nmake
I think that the problem comes from CMAKE_MAKE_PROGRAM variable it should take C:/Program Files (x86)/CodeBlocks/MinGW/bin/mingw32-make.exe, however i dont understand from where it gets the value nmake.
Even i replaced it manually I get the same problem.
My questions :
How CMake fills the Cache variables ?
Why CMAKE_MAKE_PROGRAM takes the value nmake ?
Why changing manually this variable didn t solve the problem ?
CMake fills the cache file with the values it detects based what is in CMakeLists.txt and whatever files it includes in combination with any -D paramters supplied to cmake.
On Windows CMake will default to Microsoft's nmake tool. The way to override this is by passing parameter -G"MinGW Makefiles" to cmake, or in case you use MSYS shell -G"MSYS Makefiles".
But there is a faster build tool than make called Ninja (get it from https://ninja-build.org/) which you can use by passing -GNinja to cmake.
Note: I see you're using the old MinGW that comes with Code::Blocks. There is a more up to date successor to MinGW called MinGW-w64, which supports both Windows 32-bit and 64-bit. A recent standalone build can be downloaded from https://winlibs.com/ and it also includes ninja.exe.
P.S.: If you run into more issues building the nanomsg sources after following these tips, consider passing -DNN_TESTS:BOOL=OFF to cmake

CMAKE set rc compiler flags?

CMake Version 3.4.3
Visual Studio 14 2015 Solution file
I am trying to set the location flag for rc compiler for CMAKE by using the following syntax however it is always set to the value /l"0x0409".
set(rc_flags "/l 0x809")
set(CMAKE_RC_FLAGS ${rc_flags})
Also CMAKE always sets flags for cl compiler for rc compiler which I cannot stop.
Any help would be appreciated!
Edit
I have added version of cmake and visual studio version, the command still uses the /l"0x0409" flag when using the snippet from #Florian plus it uses flags I have specified for cl.exe command for rc.exe command which is not right.
The quotation problem was fixed with CMake version 3.1 (see "0010194: setting CMAKE_RC_FLAGS has no affect on rc flags").
So I've given your example a try with CMake version 3.6.0 and the "Visual Studio 14 2015" generator and the following code:
CMakeLists.txt
cmake_minimum_required(VERSION 3.1)
project(TestRCCompilerFlags)
file(WRITE main.cpp "int main() { return 0; }")
file(WRITE main.rc "")
set(rc_flags "/l 0x809")
set(CMAKE_RC_FLAGS ${rc_flags})
add_executable(${PROJECT_NAME} main.cpp main.rc)
And - as expected - the /l 0x809 option shows up under "Project Configuration Properties/Resources/Command Line/Additional Options". So I couldn't reproduce any quotation or ignored options problems.
Makefile vs. Solution
Generally speaking the RC command line - including its flags - is defined in CMakeRCInformation.cmake. But you only have the absolute control over the RC command line if using makefile generators. There you could overwrite CMAKE_RC_COMPILE_OBJECT variable in your CMakeLists.txt file to something like:
set(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> /l 0x809 /fo<OBJECT> <SOURCE>")
The RC behavior of Visual Studio Solution generators is directly coded into cmVisualStudio10TargetGenerator::WriteRCOptions(). This code doesn't (over-)write any RC <Culture> section, so there you will always see the default /l"0x0409" there. But the <AdditionalOptions> section generated by CMake will take care of this/overwrite those defaults.