问题描述
我目前在Windows上安装CMake的,铛和忍者。我试图用CMake的生成忍者构建文件编译一个非常简单的Hello World程序。
我的CMakeLists.txt看起来是这样的:
cmake_minimum_required(版本2.8)
项目(test_project)
add_executable(主main.cpp中)
的main.cpp
是一个简单的Hello World程序。
在命令行中运行此:的CMake -G忍者..
,我得到以下错误:
- C编译器识别为锵3.5.0
clang.exe:错误:没有这样的文件或目录:/ NOLOGO
clang.exe:错误:没有这样的文件或目录:/ showIncludes
- 该CXX编译器识别为锵3.5.0
clang.exe:错误:没有这样的文件或目录:/ NOLOGO
clang.exe:错误:没有这样的文件或目录:/ showIncludes
- 检查工作使用的C编译器:忍者
- 检查工作使用C语言编译器:忍者 - 破
CMake的错误,在C:/ Program Files文件(86)/ CMake的2.8 /共享/ cmake的-2.8 /模块/ CMakeTestCCompiler.cmake:61(消息):
C编译器C:/llvm_build/RelWithDebInfo/bin/clang.exe是
不能编译一个简单的测试程序。 它失败,出现以下的输出: 更改目录:C:/ test_proj /编译/ CMakeFiles / CMakeTmp 运行构建命令:C:/ninja/ninja.exe cmTryCompileExec375034429 [1/2] C栋对象
CMakeFiles \\ cmTryCompileExec375034429.dir \\ testCCompiler.c.obj
[2/2]链接C可执行cmTryCompileExec375034429.exe
失败:CMD.EXE / C CD。 &功放;&安培;
C:\\ llvm_build \\ RelWithDebInfo \\ BIN \\ clang.exe
CMakeFiles \\ cmTryCompileExec375034429.dir \\ testCCompiler.c.obj -o
cmTryCompileExec375034429.exe&功放;&安培; CD。
clang.exe:错误:无法执行命令:程序不执行 clang.exe:错误:连接命令,退出code 1(使用-v看看失败
调用) 忍者:构建停止:子命令失败。
CMake的将不能够正确地产生这一项目。
(第一最近一次调用)调用堆栈:
的CMakeLists.txt:2(项目)
- 不完整的配置,错误发生!
另请参见C:/test_proj/build/CMakeFiles/CMakeOutput.log。
另请参见C:/test_proj/build/CMakeFiles/CMakeError.log。
的 CMakeError.log
文件看起来是这样的:
编译C编译器识别的源文件CMakeCCompilerId.c失败。
编译:C:/llvm_build/RelWithDebInfo/bin/clang.exe
建立标志:
标识标志:输出是:
1
clang.exe:错误:无法执行命令:程序不执行
clang.exe:错误:连接命令,退出code 1(使用-v看看调用)失败
编译CXX编译器识别的源文件CMakeCXXCompilerId.cpp失败。
编译:C:/ llvm_build / RelWithDebInfo /斌/铛++ EXE
建立标志:
标识标志:输出是:
1
铛++ EXE:错误:无法执行命令:程序不执行
铛++ EXE:错误:连接命令失败,退出code 1(使用-v看看调用)
确定C编译器工作失败,出现以下的输出:
更改目录:C:/ test_proj /编译/ CMakeFiles / CMakeTmp运行构建命令:C:/ninja/ninja.exe cmTryCompileExec2120850158
[1/2] C栋对象CMakeFiles \\ cmTryCompileExec2120850158.dir \\ testCCompiler.c.obj[2/2]链接C可执行cmTryCompileExec2120850158.exe失败:CMD.EXE / C CD。 &功放;&安培; C:\\ llvm_build \\ RelWithDebInfo \\ BIN \\ clang.exe CMakeFiles \\ cmTryCompileExec2120850158.dir \\ testCCompiler.c.obj -o cmTryCompileExec2120850158.exe&放大器;&安培; CD。clang.exe:错误:无法执行命令:程序不执行
clang.exe:错误:连接命令,退出code 1(使用-v看看调用)失败
忍者:构建停止:子命令失败。
看来cmake的正试图测试与Windows选项 / NOLOGO
和 / showIncludes
铛。我无法弄清楚如何告诉cmake的传递适当的参数。
FWIW我运行64位的Windows 7
编辑:
所以我通过内置的cmake的文件一看,我发现 CMakeClDeps.cmake
文件是用于添加罪魁祸首 / NOLOGO / showIncludes
选项。看来,如果我设置锵,因为编译器然后cmake的认为Visual Studio是编译器(它设置MSVC_C_ARCHITECTURE_ID到86)。
我删除了 CMakeDetermineCompilerId.cmake
,设置行 MSVC_C_ARCHITECTURE_ID
,再次尝试后,我收到以下错误:
- C编译器识别为锵3.5.0
- 该CXX编译器识别为锵3.5.0
- 检查工作使用的C编译器:忍者
- 检查工作使用C语言编译器:忍者 - 破
CMake的错误,在C:/ Program Files文件(86)/ CMake的2.8 /共享/ cmake的-2.8 /模块/ CMakeTestCCompiler.cmake:61(消息):
C编译器C:/llvm_build/RelWithDebInfo/bin/clang.exe是
不能编译一个简单的测试程序。 它失败,出现以下的输出: 更改目录:C:/ test_proj /编译/ CMakeFiles / CMakeTmp 运行构建命令:C:/ninja/ninja.exe cmTryCompileExec2815594422 [1/2] C栋对象
CMakeFiles \\ cmTryCompileExec2815594422.dir \\ testCCompiler.c.obj
[2/2]链接C可执行cmTryCompileExec2815594422.exe
失败:CMD.EXE / C CD。 &功放;&安培;
C:\\ llvm_build \\ RelWithDebInfo \\ BIN \\ clang.exe
CMakeFiles \\ cmTryCompileExec2815594422.dir \\ testCCompiler.c.obj -o
cmTryCompileExec2815594422.exe&功放;&安培; CD。
clang.exe:错误:无法执行命令:程序不执行 clang.exe:错误:连接命令,退出code 1(使用-v看看失败
调用) 忍者:构建停止:子命令失败。
CMake的将不能够正确地产生这一项目。
(第一最近一次调用)调用堆栈:
的CMakeLists.txt:2(项目)
- 不完整的配置,错误发生!
另请参见C:/test_proj/build/CMakeFiles/CMakeOutput.log。
另请参见C:/test_proj/build/CMakeFiles/CMakeError.log。
原来第二盘我收到是因为铛找不到链接错误。我已经建立了使用Visual Studio的叮当声,但在当时却找不到在Visual Studio连接。我所要做的就是在Visual Studio开发控制台运行它。
CMake的仍然认为是铿锵一个Visual Studio编译器,在 CMakeDetermineCompilerId.cmake
文件中有一条线,看起来像这样:
设置(MSVC _ $ {}郎_ARCHITECTURE_ID$ {ARCHITECTURE_ID})
和我改成了这个样子
如果(COMPILER_ID匹配MSVC)
集(MSVC _ $ {}郎_ARCHITECTURE_ID$ {ARCHITECTURE_ID})
万一()
希望这不会破坏任何其他CMake的功能。
I currently have cmake, clang and ninja installed on windows. I am trying to use CMake to generate a ninja build file to compile a very simple hello world program.
My CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 2.8)
project(test_project)
add_executable(main main.cpp)
main.cpp
is a simple hello world program.
On the command line I run this: cmake -G Ninja ..
and I get the following errors:
-- The C compiler identification is Clang 3.5.0
clang.exe: error: no such file or directory: '/nologo'
clang.exe: error: no such file or directory: '/showIncludes'
-- The CXX compiler identification is Clang 3.5.0
clang.exe: error: no such file or directory: '/nologo'
clang.exe: error: no such file or directory: '/showIncludes'
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "C:/llvm_build/RelWithDebInfo/bin/clang.exe" is
not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/test_proj/build/CMakeFiles/CMakeTmp
Run Build Command:C:/ninja/ninja.exe cmTryCompileExec375034429
[1/2] Building C object
CMakeFiles\cmTryCompileExec375034429.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTryCompileExec375034429.exe
FAILED: cmd.exe /c cd . &&
C:\llvm_build\RelWithDebInfo\bin\clang.exe
CMakeFiles\cmTryCompileExec375034429.dir\testCCompiler.c.obj -o
cmTryCompileExec375034429.exe && cd .
clang.exe: error: unable to execute command: program not executable
clang.exe: error: linker command failed with exit code 1 (use -v to see
invocation)
ninja: build stopped: subcommand failed.
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:/test_proj/build/CMakeFiles/CMakeOutput.log".
See also "C:/test_proj/build/CMakeFiles/CMakeError.log".
The CMakeError.log
file looks like this:
Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: C:/llvm_build/RelWithDebInfo/bin/clang.exe
Build flags:
Id flags:
The output was:
1
clang.exe: error: unable to execute command: program not executable
clang.exe: error: linker command failed with exit code 1 (use -v to see invocation)
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: C:/llvm_build/RelWithDebInfo/bin/clang++.exe
Build flags:
Id flags:
The output was:
1
clang++.exe: error: unable to execute command: program not executable
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
Determining if the C compiler works failed with the following output:
Change Dir: C:/test_proj/build/CMakeFiles/CMakeTmp
Run Build Command:C:/ninja/ninja.exe cmTryCompileExec2120850158
[1/2] Building C object CMakeFiles\cmTryCompileExec2120850158.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTryCompileExec2120850158.exe
FAILED: cmd.exe /c cd . && C:\llvm_build\RelWithDebInfo\bin\clang.exe CMakeFiles\cmTryCompileExec2120850158.dir\testCCompiler.c.obj -o cmTryCompileExec2120850158.exe && cd .
clang.exe: error: unable to execute command: program not executable
clang.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
It appears that cmake is trying to test clang with windows options /nologo
and /showIncludes
. I cannot figure out how to tell cmake to pass the proper arguments.
FWIW I'm running 64bit Windows 7
EDIT:
So I looked through the built in cmake files and I found that the CMakeClDeps.cmake
file was the culprit for adding the /nologo /showIncludes
options. It appears that if I set Clang as the compiler then cmake thinks that visual studio is the compiler (it sets MSVC_C_ARCHITECTURE_ID to x86).
I removed the line in CMakeDetermineCompilerId.cmake
that sets MSVC_C_ARCHITECTURE_ID
and after trying again I get the following errors:
-- The C compiler identification is Clang 3.5.0
-- The CXX compiler identification is Clang 3.5.0
-- Check for working C compiler using: Ninja
-- Check for working C compiler using: Ninja -- broken
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "C:/llvm_build/RelWithDebInfo/bin/clang.exe" is
not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/test_proj/build/CMakeFiles/CMakeTmp
Run Build Command:C:/ninja/ninja.exe cmTryCompileExec2815594422
[1/2] Building C object
CMakeFiles\cmTryCompileExec2815594422.dir\testCCompiler.c.obj
[2/2] Linking C executable cmTryCompileExec2815594422.exe
FAILED: cmd.exe /c cd . &&
C:\llvm_build\RelWithDebInfo\bin\clang.exe
CMakeFiles\cmTryCompileExec2815594422.dir\testCCompiler.c.obj -o
cmTryCompileExec2815594422.exe && cd .
clang.exe: error: unable to execute command: program not executable
clang.exe: error: linker command failed with exit code 1 (use -v to see
invocation)
ninja: build stopped: subcommand failed.
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:/test_proj/build/CMakeFiles/CMakeOutput.log".
See also "C:/test_proj/build/CMakeFiles/CMakeError.log".
Turns out the second set of errors I received were because clang could not find the linker. I had built clang using visual studio but at the time it couldn't find the visual studio linker. All I had to do was run it in the visual studio development console.
CMake still thinks that clang is a visual studio compiler so in the CMakeDetermineCompilerId.cmake
file there is a line that looks like this:
set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}")
and I changed it to look like this
if (COMPILER_ID MATCHES "MSVC")
set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}")
endif()
Hopefully this doesn't break any other CMake functionality.
这篇关于在Windows上编译C ++项目,CMake的,锵和忍者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!