Création d'un projet c ++ sous Windows avec CMake, Clang et Ninja
J'ai actuellement cmake, clang et ninja installé sur windows. Je suis en train d'utiliser CMake pour générer un ninja fichier de compilation pour compiler un très simple programme "hello world".
Mon CMakeLists.txt ressemble à ceci:
cmake_minimum_required(VERSION 2.8)
project(test_project)
add_executable(main main.cpp)
main.cpp
est un simple programme "hello world".
Sur la ligne de commande je l'exécute: cmake -G Ninja ..
et j'obtiens les erreurs suivantes:
-- 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".
La CMakeError.log
fichier ressemble à ceci:
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.
Il semble que cmake est en train de tester, clang avec les options windows /nologo
et /showIncludes
. Je ne peux pas comprendre comment le dire à cmake pour passer les arguments appropriés.
FWIW, je suis en cours d'exécution 64 bits de Windows 7
EDIT:
J'ai donc regardé à travers les construit dans cmake fichiers et j'ai trouvé que le CMakeClDeps.cmake
fichier a été le coupable pour l'ajout de la /nologo /showIncludes
options. Il apparaît que si j'ai mis Clang comme le compilateur puis cmake pense que visual studio est le compilateur (il définit MSVC_C_ARCHITECTURE_ID x86).
J'ai supprimé la ligne dans CMakeDetermineCompilerId.cmake
qui définit MSVC_C_ARCHITECTURE_ID
et après avoir essayé de nouveau, j'obtiens les erreurs suivantes:
-- 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".
source d'informationauteur miningold
Vous devez vous connecter pour publier un commentaire.
Ne sais pas si cela peut être utile, mais j'ai eu le même message d'erreur. Maintenant, je peux compiler avec clang(3.7.1)/ninja(1.6)/cmake(3.4.1) sur Windows d'effectuer les actions suivantes dans un répertoire de construction:
"<Your Visual Studio location>\VC\vcvarsall.bat" x86
)clang-cl
(au lieu declang
etclang++
)cmake -G Ninja <project>
cmake --build .
S'avère que la deuxième série d'erreurs que j'ai reçus étaient parce que clang ne pouvait pas trouver l'éditeur de liens. J'avais construit clang l'aide de visual studio, mais à l'époque il ne trouve pas de visual studio de l'éditeur de liens. Tout ce que j'avais à faire était de le lancer dans le développement visual studio de la console.
CMake pense toujours que clang est un compilateur visual studio, donc, dans le
CMakeDetermineCompilerId.cmake
fichier il y a une ligne qui ressemble à ceci:set(MSVC_${lang}_ARCHITECTURE_ID "${ARCHITECTURE_ID}")
et je l'ai changé pour ressembler à ce
J'espère que ce n'est pas tout casser autres CMake fonctionnalité.