2016-12-20 49 views
-1

我正在Windows上使用Clang 3.8和CMake 3.7构建一个C++项目,但Clang在配置发出错误,如下所示。Windows上的Clang和CMake

 
    Determining if the CXX compiler works failed with the following output: 
    Change Dir: C:/tools/k.build/CMakeFiles/CMakeTmp 

    Run Build Command:"C:/tools/ninja.exe" "cmTC_c0004" 
    [1/2] Building CXX object CMakeFiles/cmTC_c0004.dir/testCXXCompiler.cxx.obj 
    [2/2] Linking CXX executable cmTC_c0004.exe 

    FAILED: cmTC_c0004.exe 

    cmd.exe /C "cd . && C:\tools\llvm-3.8.1.build\Release\bin\clang++.exe  CMakeFiles/cmTC_c0004.dir/testCXXCompiler.cxx.obj -o cmTC_c0004.exe -Wl,--out-implib,libcmTC_c0004.dll.a -Wl,--major-image-version,0,--minor-image-version,0 && cd ." 

    LINK : warning LNK4044: unrecognized option '/-out-implib'; ignored 
    LINK : warning LNK4044: unrecognized option '/-major-image-version'; ignored 
    LINK : warning LNK4044: unrecognized option '/-minor-image-version'; ignored 
    LINK : fatal error LNK1181: cannot open input file 'libcmTC_c0004.dll.a' 

    clang++.exe: error: linker command failed with exit code 1181 (use -v to see invocation) 

    ninja: build stopped: subcommand failed. 

奇怪的是CMakeFiles/CMakeTmp /中没有文件存在。我怎样才能使它工作?

+2

您是否尝试删除二进制输出'k.build'并再次尝试从头开始?看起来像你切换编译器,例如从'gcc'到'clang'放在同一个输出目录中。你也可以尝试一个最小的例子,像[这里](http://stackoverflow.com/questions/38171878/how-do-i-tell-cmake-to-use-clang-on-windows)。 – Florian

+0

不知何故,您的配置已损坏。以'/ -'开始的选项显然是错误的,'.dll.a'也看起来很奇怪。你如何引用CMake?它检测到什么编译器? – usr1234567

+0

@Florian是的,我删除了k.build中的输出,并尝试了一次又一次的其他设置。这些项目是为Linux开发的,我将它移植到Windows上。 – HenryK

回答

0

简而言之,您正在定义您的工具链错误。 CMake认为你正在使用不同路径的MSVC编译器。详细的答案见this question。请注意,您仍然需要MSVC或Cygwin作为构建环境。

+0

你的意思是说MSVC或Cygwin是CMAKE_GENERATOR所必需的吗?忍者不能使用? – HenryK

+0

我不知道。链接的问题表明需要构建管理器(如MSVC或Cygwin)。我知道CMake已经添加了忍者支持,因为这个问题得到了回答。我认为最主要的是以答案建议的方式添加工具链信息,而不是您使用的方法。 –