Getting fatal error: 'type_traits' file not found #include <type_traits>, while building clang example

对着背影说爱祢 提交于 2020-01-01 18:54:33

问题


I am trying to build the PrintFunctionNames example from clang. However I get the following error:

[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>

System Info:

clang version 4.0.0 (http://llvm.org/git/clang.git 6197d01def79876e2c1670ced871e10b12c36241) (http://llvm.org/git/llvm.git 24f7cd87f70ddcc91d50f77e405420c0c27853fd) Target: x86_64-apple-darwin15.6.0 Thread model: posix InstalledDir: /usr/local/bin

OSX 10.11.6

Edit 1:

on making the changes suggested by Alex, I start getting header issues. On fixing it via includes, same error is thrown again

% 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.

回答1:


OS X (macOS) has a bit different approach. You can have several Xcode installed and you compile for different platforms. You should use -isysroot option to explicitly specify against which SDK to build.

The following command should do the trick

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

Otherwise, please check which SDKs are installed and change the value of isysroot to correspond to your setup.



来源:https://stackoverflow.com/questions/38960314/getting-fatal-error-type-traits-file-not-found-include-type-traits-while

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!