【问题标题】:Getting fatal error: 'type_traits' file not found #include <type_traits>, while building clang example出现致命错误:在构建 clang 示例时找不到“type_traits”文件#include <type_traits>
【发布时间】:2016-12-21 23:13:29
【问题描述】:

我正在尝试从 clang 构建 PrintFunctionNames 示例。 但是我收到以下错误:

[mac-osx:clang/examples/PrintFunctionNames] osx% clang++ -std=c++0x PrintFunctionNames.cpp
In file included from PrintFunctionNames.cpp:15:
In file included from /usr/local/include/clang/Frontend/FrontendPluginRegistry.h:13:
In file included from /usr/local/include/clang/Frontend/FrontendAction.h:22:
In file included from /usr/local/include/clang/Basic/LLVM.h:22:
In file included from /usr/local/include/llvm/Support/Casting.h:19:
/usr/local/include/llvm/Support/type_traits.h:17:10: fatal error: 'type_traits' file not found
#include <type_traits>

系统信息:

clang 版本 4.0.0 (http://llvm.org/git/clang.git6197d01def79876e2c1670ced871e10b12c36241) (http://llvm.org/git/llvm.git24f7cd87f70ddcc91d50f77e405420c0c27853fd) 目标:x86_64-apple-darwin15.6.0 线程模型:posix 安装目录:/usr/local/bin

OSX 10.11.6

编辑 1:

在进行 Alex 建议的更改时,我开始遇到标题问题。通过包含修复它时,再次抛出相同的错误

% clang++ -std=c++0x PrintFunctionNames.cpp -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -I../../../clang/include -I../../../../include -I../../../../../build/include
In file included from PrintFunctionNames.cpp:15:
In file included from ../../../clang/include/clang/Frontend/FrontendPluginRegistry.h:13:
In file included from ../../../clang/include/clang/Frontend/FrontendAction.h:22:
In file included from ../../../clang/include/clang/Basic/LLVM.h:22:
In file included from ../../../../include/llvm/Support/Casting.h:19:
../../../../include/llvm/Support/type_traits.h:17:10: fatal error: 'type_traits' file not found
#include <type_traits>
         ^
1 error generated.

【问题讨论】:

  • 您能否也发布来自clang++ -v -std=c++0x PrintFunctionNames.cpp 的输出?现在我认为 isysroot 没有任何区别

标签: c++ macos c++11 clang llvm-clang


【解决方案1】:

OS X (macOS) 有一些不同的方法。您可以安装多个 Xcode,并针对不同的平台进行编译。 您应该使用 -isysroot 选项来明确指定要构建的 SDK。

下面的命令应该可以解决问题

clang++ -std=c++0x PrintFunctionNames.cpp -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk

否则,请检查安装了哪些 SDK,并根据您的设置更改 isysroot 的值。

【讨论】:

  • 在进行建议的更改时,编译开始抛出未找到标头的错误。在通过 -I 专门添加它们时,再次抛出 type_trait 问题。 @AlexDenisov,请检查编辑 1。希望我能够解释这个问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-12-11
  • 2012-10-24
  • 2013-05-15
  • 1970-01-01
  • 1970-01-01
  • 2016-08-02
  • 2018-07-24
相关资源
最近更新 更多