我安装了Xcode 4.3并想测试这个C ++ 11程序:
#include <type_traits>
int main()
{
}
但是,它找不到type_traits
标题:
~ $ c++ -o test main.cpp
main.cpp:1:10: fatal error: 'type_traits' file not found
#include <type_traits>
^
1 error generated.
似乎我正在使用正确的编译器:
~ $ c++ -v
Apple clang version 3.1 (tags/Apple/clang-318.0.45) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.3.0
Thread model: posix
我检查了默认的包含路径:
~ $ `c++ --print-prog-name=cc1plus` -v
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin11"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/../../../../i686-apple-darwin11/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/usr/local/include
/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
以上路径确实不包含type_traits
标头。搜索命令显示可以在两个位置找到:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/include/c++/v1/type_traits
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/type_traits
我的编译器默认值显然有问题。如何配置我的编译器以便在正确的位置找到type_traits
标头?
关注@ sehe的建议:
~ $ clang++ -v -fshow-source-location -std=c++0x main.cpp
Apple clang version 3.1 (tags/Apple/clang-318.0.45) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.3.0
Thread model: posix
"/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.7.3 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name main.cpp -pic-level 1 -mdisable-fp-elim -relaxed-aliasing -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 128.2 -v -resource-dir /usr/bin/../lib/clang/3.1 -fmodule-cache-path /var/folders/d6/sf96r2ps457230x3v8yj52s40000gp/T/clang-module-cache -std=c++0x -fdeprecated-macro -fdebug-compilation-dir /Users/francis -ferror-limit 19 -fmessage-length 174 -stack-protector 1 -fblocks -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-dispatch-method=mixed -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/d6/sf96r2ps457230x3v8yj52s40000gp/T/main-sUcT7k.o -x c++ main.cpp
clang -cc1 version 3.1 based upon llvm 3.1svn default target x86_64-apple-darwin11.3.0
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64"
ignoring nonexistent directory "/usr/include/c++/4.0.0"
ignoring nonexistent directory "/usr/include/c++/4.0.0/i686-apple-darwin8/"
ignoring nonexistent directory "/usr/include/c++/4.0.0/backward"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/usr/local/include
/usr/bin/../lib/clang/3.1/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
main.cpp:1:10: fatal error: 'type_traits' file not found
#include <type_traits>
^
1 error generated.
它似乎根本没有查看Xcode.app包。
一个可能的原因是我安装了Xcode和“Xcode的命令行工具”。后者在/usr
文件夹中安装了二进制文件。
我刚发现type_traits
标题也可以在/usr/include
中找到:
~ $ find /usr/include -type f -name type_traits
/usr/include/c++/4.2.1/tr1/type_traits
/usr/include/c++/v1/type_traits
答案 0 :(得分:25)
答案 1 :(得分:6)
在Xcode中使用新的C ++ 11标准库: