15

現在、Windowsにcmake、clang、およびninjaがインストールされています。CMake を使用して忍者ビルド ファイルを生成し、非常に単純な hello world プログラムをコンパイルしようとしています。

私の CMakeLists.txt は次のようになります。

cmake_minimum_required(VERSION 2.8)
project(test_project)
add_executable(main main.cpp)

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

ファイルは次の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.

cmake は、Windows オプション/nologoとで clang をテストしようとしているよう/showIncludesです。cmakeに適切な引数を渡すように指示する方法がわかりません。

FWIW私は64ビットのWindows 7を実行しています

編集:

それで、組み込みのcmakeファイルを調べたところ、そのファイルがオプションCMakeClDeps.cmakeを追加する原因であることがわかりました。/nologo /showIncludesClang をコンパイラとして設定すると、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".
4

2 に答える 2

7

参考になるかわかりませんが、同じエラーが発生しました。これで、ビルド ディレクトリで次のアクションを実行して、Windows で clang(3.7.1)/ninja(1.6)/cmake(3.4.1) でコンパイルできます。

  1. 関連する vcvarsXX.bat ファイルをロードします (例: "<Your Visual Studio location>\VC\vcvarsall.bat" x86)
  2. CC と CXX の両方をclang-cl( と の代わりにclang)clang++に設定します。
  3. 走るcmake -G Ninja <project>
  4. 走るcmake --build .
于 2016-03-09T14:33:14.530 に答える
3

私が受け取った 2 番目のエラー セットは、clang がリンカーを見つけられなかったことが原因であることがわかりました。Visual Studio を使用して clang をビルドしましたが、その時点で Visual Studio リンカが見つかりませんでした。私がしなければならなかったのは、Visual Studio 開発コンソールで実行することだけでした。

CMake は依然として clang がビジュアル スタジオ コンパイラであると考えているため、CMakeDetermineCompilerId.cmakeファイルには次のような行があります。

set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}")

そして、私はそれを次のように変更しました

if (COMPILER_ID MATCHES "MSVC")
  set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}")
endif()

これにより、他の CMake 機能が損なわれないことを願っています。

于 2014-03-23T15:49:39.107 に答える