【问题标题】:CMake with VIsual Studio 2015 and ClangCMake 与 VIsual Studio 2015 和 Clang
【发布时间】:2016-09-19 17:19:45
【问题描述】:

我是 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 上,实际上遇到了一个不同的错误(我不记得了,因为我没有记录它)。经过一些 Google 研究后,我决定安装 VS2015 的 Update 2,希望它能解决问题,但它只会导致另一个错误,即您在上面看到的错误。

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

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

【问题讨论】:

  • 你有没有得到这个排序的答案?我收到关于 Element &lt;DebugInformationFormat&gt; has an invalid value of "ProgramDatabase". 的非常相似的错误
  • 很遗憾,我并没有解决问题本身,而是发现了一些东西。首先,Visual Studio 实际上希望项目中的所有属性都与您使用的编译器兼容。因此,例如,要将 clang 的警告级别设置为最大,您可以使用 -Weverything 而不是 /W4。使用 cmake 手动设置标志时必须考虑这一点。否则,您到处都会遇到那些“无效值”错误。我正在做的(目前)是在 CMake 中使用其默认工具集生成解决方案,然后在 VS 中手动更改工具集和错误标志。效果很好。

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


【解决方案1】:

只是为了回答上面关于Element &lt;DebugInformationFormat&gt; has an invalid value of "ProgramDatabase" 的cmets 中的@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++ 或链接器部分中的设置并查看建议值。基本上,您可以使用典型的 linux 选项进行 clang。另外,还有一些以ms-为前缀的选项,您可以在项目的属性中找到它们。

【讨论】:

  • 非常感谢。
  • 我实际上能够在 VS2015 的项目属性区域中解决这个问题,但是要恢复确切的步骤将是一个挑战。如果我找到该信息,我会回复。
【解决方案2】:

问题很可能与旧的 Windows SDK 使用有关。使用Configuration Properties -&gt; General -&gt; Windows SDK Version中最后一个可用的Windows SDK

【讨论】:

  • 这很有可能。自创建此主题以来,还出现了新版本的 CMake,据我最近的测试可知,这些似乎不再导致错误。尽管我假设您只是应该手动转换命令行参数,但您仍然会收到“无效参数”错误。这有点复杂,但应该可以。
猜你喜欢
  • 2018-06-08
  • 2017-05-10
  • 1970-01-01
  • 2016-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-16
  • 1970-01-01
相关资源
最近更新 更多