Xcode 4.3 和 C++11 包含路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9345271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode 4.3 and C++11 include paths
提问by StackedCrooked
I installed Xcode 4.3 and want to test this C++11 program:
我安装了 Xcode 4.3 并想测试这个 C++11 程序:
#include <type_traits>
int main()
{
}
However, it doesn't find the type_traits
header:
但是,它没有找到type_traits
标题:
~ $ c++ -o test main.cpp
main.cpp:1:10: fatal error: 'type_traits' file not found
#include <type_traits>
^
1 error generated.
It seems that I am using the correct compiler:
看来我正在使用正确的编译器:
~ $ 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
I checked the default include paths:
我检查了默认的包含路径:
~ $ `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.
Above paths do indeed not contain the type_traits
headers. A search command reveals that can be found in two locations:
上面的路径确实不包含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
Apparently something is wrong with my compiler defaults. How can I configure my compiler so that it finds the type_traits
header in the right location?
显然,我的编译器默认设置有问题。如何配置我的编译器,以便它type_traits
在正确的位置找到标头?
Update
更新
Following @sehe's suggestion:
遵循@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.
It doesn't seem to look in the Xcode.app bundle at all.
它似乎根本没有查看 Xcode.app 包。
One possible reason is that I installed both Xcode and the "Command line tools for Xcode". The latter installed binaries in the /usr
folder.
一个可能的原因是我同时安装了 Xcode 和“Xcode 命令行工具”。后者在/usr
文件夹中安装了二进制文件。
I just found that the type_traits
header can also be found in /usr/include
:
我刚刚发现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
采纳答案by Howard Hinnant
回答by John Brewer
Howard Hinnant's answer (with corrections) is the correct answer for the command line.
Howard Hinnant 的答案(有更正)是命令行的正确答案。
To use the new C++11 standard library inside of Xcode:
要在 Xcode 中使用新的 C++11 标准库:
- In the Build Settings tab for your project, scroll down to "Apple LLVM Compiler 4.1 - Language"
- Set the setting "C++ Language Dialect" to "C++11 [-std=c++11]"
- Set the setting "C++ Standard Library" to "libc++ (LLVM standard C++ library with C++11 support)"
- 在项目的 Build Settings 选项卡中,向下滚动到“Apple LLVM Compiler 4.1 - Language”
- 将设置“C++ 语言方言”设置为“C++11 [-std=c++11]”
- 将设置“C++ 标准库”设置为“libc++(支持 C++11 的 LLVM 标准 C++ 库)”