min*_*old 15 c++ windows build clang ninja
我目前在Windows上安装了cmake,clang和ninja.我正在尝试使用CMake生成一个忍者构建文件来编译一个非常简单的hello world程序.
我的CMakeLists.txt看起来像这样:
cmake_minimum_required(VERSION 2.8)
project(test_project)
add_executable(main main.cpp)
Run Code Online (Sandbox Code Playgroud)
main.cpp 是一个简单的hello world程序.
在命令行上我运行这个:cmake -G Ninja ..我得到以下错误:
-- 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".
Run Code Online (Sandbox Code Playgroud)
该CMakeError.log文件如下所示:
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.
Run Code Online (Sandbox Code Playgroud)
看来cmake的试图测试与Windows选项铛/nologo和/showIncludes.我无法弄清楚如何告诉cmake传递正确的参数.
FWIW我正在运行64位Windows 7
编辑:
所以我浏览了内置的cmake文件,发现该CMakeClDeps.cmake文件是添加/nologo /showIncludes选项的罪魁祸首.看来如果我将Clang设置为编译器,那么cmake认为visual studio是编译器(它将MSVC_C_ARCHITECTURE_ID设置为x86).
我删除了CMakeDetermineCompilerId.cmake那些集合中的行,MSVC_C_ARCHITECTURE_ID然后再次尝试我得到以下错误:
-- 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".
Run Code Online (Sandbox Code Playgroud)
不知道它是否有用,但我有同样的错误.现在我可以在Windows上使用clang(3.7.1)/ ninja(1.6)/ cmake(3.4.1)进行编译,在构建目录中执行以下操作:
"<Your Visual Studio location>\VC\vcvarsall.bat" x86)clang-cl(而不是clang和clang++)cmake -G Ninja <project>cmake --build .结果我收到的第二组错误是因为 clang 找不到链接器。我使用 Visual Studio 构建了 clang,但当时它找不到 Visual Studio 链接器。我所要做的就是在 Visual Studio 开发控制台中运行它。
CMake 仍然认为 clang 是一个 Visual Studio 编译器,因此在CMakeDetermineCompilerId.cmake文件中有一行如下所示:
set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}")
我把它改成了这样
if (COMPILER_ID MATCHES "MSVC")
set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}")
endif()
Run Code Online (Sandbox Code Playgroud)
希望这不会破坏任何其他 CMake 功能。
| 归档时间: |
|
| 查看次数: |
11676 次 |
| 最近记录: |