Xcode 4.3和C ++ 11包括路径 [英] Xcode 4.3 and C++11 include paths
问题描述
我安装了Xcode 4.3并想测试这个C ++ 11程序:
I installed Xcode 4.3 and want to test this C++11 program:
#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.
看来我使用的是正确的编译器:
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
:
~ $ `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
标题。搜索命令显示可以在两个位置找到:
Above paths do indeed not contain the type_traits
headers. A search command reveals that can be found in two locations:
/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
头?
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?
遵循@ sehe的建议:
Following @sehe's suggestion:
~ $ 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包。
It doesn't seem to look in the Xcode.app bundle at all.
一个可能的原因是我安装了Xcode和Xcode的命令行工具。后者在 / usr
文件夹中安装了二进制文件。
One possible reason is that I installed both Xcode and the "Command line tools for Xcode". The latter installed binaries in the /usr
folder.
我刚刚发现 type_traits
标题也可以在 / usr / include
中找到:
I just found that the type_traits
header can also be found in /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
更新2
感谢@sehe ,@rob和@Howard我发现这个工作原理:
Update 2
Thanks to @sehe, @rob and @Howard I found that this works:
clang++ -stdlib=libc++ -o test main.cpp
推荐答案
您需要:
-std=c++0x
选择C ++ 11。您需要:
to select C++11. And you need:
-stdlib=libc++
以选择 libc ++ 。默认情况下,使用gcc 4.2附带的std :: lib,它是pre-C ++ 11。
to select libc++. By default, the std::lib that shipped with gcc 4.2 is used, which is pre-C++11.
这篇关于Xcode 4.3和C ++ 11包括路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!