使用VIsual Studio 2015和Clang进行CMake

时间:2016-05-22 23:18:20

标签: visual-studio visual-studio-2015 cmake clang cmake-gui

我是CMake的初学者,最近刚刚将我当前的项目从Visual Studio 2015解决方案迁移到CMake项目。我花了几天时间,但现在我正处于我的项目完全迁移的地步,生成的Visual Studio解决方案看起来和感觉完全像原始解决方案。使用MSVC和平台工具集v140时,我仍然可以构建我的项目。在完成所有这些之后,我想通过使用不同的编译器构建我的项目来尝试CMake的好处。特别是,在我的项目中有一些与模板相关的代码,我认为它不是非常符合标准的,所以我想用Clang构建它,我知道它比MSVC在模板相关的东西上更严格。为此,我启动了CMake GUI,选择了源代码和二进制路径,单击配置,选择“Visual Studio 14 2015”并在平台工具集字段中键入“v140_clang_3_7”,保持所有其他设置不变。

不幸的是,在执行此操作时,CMake无法配置(并生成)我的解决方案,并出现以下错误:

The C compiler identification is Clang 3.7.0
The CXX compiler identification is Clang 3.7.0
Check for working C compiler using: Visual Studio 14 2015
Check for working C compiler using: Visual Studio 14 2015 -- broken
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.5/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler "C:/Program Files (x86)/Microsoft Visual Studio
  14.0/VC/bin/cl.exe" is not able to compile a simple test program.

  It fails with the following output:

   Change Dir: C:/Users/marku/Desktop/build_muell/CMakeFiles/CMakeTmp



  Run Build Command:"C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe"
  "cmTC_c4641.vcxproj" "/p:Configuration=Debug" "/p:VisualStudioVersion=14.0"

  Microsoft (R)-Buildmodul, Version 14.0.25123.0


  Copyright (C) Microsoft Corporation.  Alle Rechte vorbehalten.





  Der Buildvorgang wurde am Mo, 23.05.2016 00:52:13 gestartet.


  Das in einem BeforeTargets-Attribut bei "C:\Program Files
  (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets
  (34,37)" aufgef�hrte Ziel "_ConvertPdbFiles" ist nicht im Projekt vorhanden
  und wird daher ignoriert.


  Das in einem AfterTargets-Attribut bei "C:\Program Files
  (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets
  (34,70)" aufgef�hrte Ziel "_CollectPdbFiles" ist nicht im Projekt vorhanden
  und wird daher ignoriert.


  Das in einem BeforeTargets-Attribut bei "C:\Program Files
  (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets
  (40,38)" aufgef�hrte Ziel "_CollectMdbFiles" ist nicht im Projekt vorhanden
  und wird daher ignoriert.


  Das in einem AfterTargets-Attribut bei "C:\Program Files
  (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets
  (40,71)" aufgef�hrte Ziel "_CopyMdbFiles" ist nicht im Projekt vorhanden
  und wird daher ignoriert.


  Projekt
  "C:\Users\marku\Desktop\build_muell\CMakeFiles\CMakeTmp\cmTC_c4641.vcxproj"
  auf Knoten "1" (Standardziele).


  PrepareForBuild:


    Das Verzeichnis "cmTC_c4641.dir\Debug\" wird erstellt.

    Das Verzeichnis "C:\Users\marku\Desktop\build_muell\CMakeFiles\CMakeTmp\Debug\" wird erstellt.

    Das Verzeichnis "cmTC_c4641.dir\Debug\cmTC_c4641.tlog\" wird erstellt.


  InitializeBuildStatus:


    "cmTC_c4641.dir\Debug\cmTC_c4641.tlog\unsuccessfulbuild" wird erstellt, da "AlwaysCreate" angegeben wurde.


  C:\Program Files
  (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Clang.targets(210,5):
  error : Element <DebugInformationFormat> has an invalid value of
  "ProgramDatabase".
  [C:\Users\marku\Desktop\build_muell\CMakeFiles\CMakeTmp\cmTC_c4641.vcxproj]



  Die Erstellung des Projekts
  "C:\Users\marku\Desktop\build_muell\CMakeFiles\CMakeTmp\cmTC_c4641.vcxproj"
  ist abgeschlossen (Standardziele) -- FEHLER.





  Fehler beim Buildvorgang.






  "C:\Users\marku\Desktop\build_muell\CMakeFiles\CMakeTmp\cmTC_c4641.vcxproj"
  (Standardziel) (1) ->


  (ClCompile Ziel) -> 


    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Clang.targets(210,5): error : Element <DebugInformationFormat> has an invalid value of "ProgramDatabase". [C:\Users\marku\Desktop\build_muell\CMakeFiles\CMakeTmp\cmTC_c4641.vcxproj]





      0 Warnung(en)

      1 Fehler





  Verstrichene Zeit 00:00:00.70






  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt


Configuring incomplete, errors occurred!
See also "C:/Users/marku/Desktop/build_muell/CMakeFiles/CMakeOutput.log".
See also "C:/Users/marku/Desktop/build_muell/CMakeFiles/CMakeError.log".

现在我不知道这个错误的含义是什么或者是什么导致它,除了CMake显然正在尝试编译一个失败的测试程序。错误日志中的“Xamarin”内容特别不合适。我已经尝试了几个方法来解决这个问题。最初,我在Visual Studio 2015 Update 1上实际上遇到了一个不同的错误(我不记得了,因为我没有记录它)。经过一些谷歌研究,我决定安装VS2015的Update 2,希望它可以解决问题,但它只会导致一个不同的错误,这是你在上面看到的错误。

出于好奇,我还采用了我原来的VS解决方案并尝试将平台工具集设置为Clang。它仍然没有编译,但至少它给了我一个合理的错误信息,实际上对我有用(提到解决方案的“警告级别”属性有一个它没有预料到的值)。但是,有了这个错误日志,我甚至不知道从哪里开始寻找问题的根源。

现在我可以在这里分享我的CMake代码,但我不确定这是否有用。项目代码分为多个文件,因此共享它有点复杂,我也不确定是否可以在CMake文件中找到问题的原因。我实际上假设问题的原因可能与项目代码本身无关。我试图谷歌搜索有关此错误的信息,但不幸的是我得到的所有内容都是五次点击,所有这些只包含上面的错误日志,没有解决问题的方法。我不知道从哪里开始寻找。任何人都有这方面的经验,可以带领我走向正确的方向吗?如果您有任何想法或希望看到我的任何代码可以帮助您找到错误原因,请告诉我。

2 个答案:

答案 0 :(得分:6)

在关于Element <DebugInformationFormat> has an invalid value of "ProgramDatabase"的评论中回答上面的@jml问题。您应该更改编译器命令行参数。例如,DebugInformationFormat = ProgramDatabase是cl编译器的/ Zi选项,对于clang是未知的。对于它你应该使用“-g2 -gdwarf-2”。对于例外,cl使用/ EHsc,但对于clang,它应该是-fexceptions。在我的cmake文件中,我执行了以下操作:

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
    set(CMAKE_CXX_FLAGS_DEBUG   "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -g2 -gdwarf-2 -fexceptions")
else ()
    # for cl.exe
endif ()

找出这些选项的最简单方法是打开任何项目的属性,并浏览C ++或Linker部分中的设置并观察建议值。基本上你可以使用典型的linux选项进行clang。此外,还有一些前缀为ms-的选项,您可以在项目的属性中找到它们。

答案 1 :(得分:0)

最有可能的是,问题与旧的Windows SDK使用有关。使用Configuration Properties -> General -> Windows SDK Version

中最后一个可用的Windows SDK