Xcode 编译器找不到 C++ 11 包含
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19089293/
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 compiler cannot find C++ 11 includes
提问by Martin Schlott
I developed some classes in Visual Studio 2012 which make heavy use of C++11 features and also uses new std features like threads and mutex. The reason was to be platform independent. Trying to port the code to OSX the Xcode compiler 5.0 cannot open following includes:
我在 Visual Studio 2012 中开发了一些类,这些类大量使用了 C++11 功能,还使用了新的 std 功能,如线程和互斥锁。原因是平台独立。尝试将代码移植到 OSX 时,Xcode 编译器 5.0 无法打开以下内容:
#include <chrono>
#include <thread>
#include <functional>
#include <mutex>
I already switch the build settings to C++11 and searched the usr/include path for the includes. Please do not suggest boost as I try to eliminate it from my projects.
我已经将构建设置切换到 C++11 并搜索了包含的 usr/include 路径。请不要建议提升,因为我试图从我的项目中消除它。
回答by trojanfoe
You need both -std=c++11
and -stdlib=libc++
:
你需要-std=c++11
和-stdlib=libc++
:
$ cat cpptest.cpp
#include <chrono>
#include <thread>
#include <functional>
#include <mutex>
int main() {
return 0;
}
$ clang -o cpptest -std=c++11 -stdlib=libc++ cpptest.cpp
$ echo $?
0
回答by the_mandrill
Give that you're using Xcode, you shouldn't need to specify explicit flags to clang
or add build paths to /usr/include
, as that is done for you by the IDE. What you need to do is open the project settings -> Build Settings and set C++ Language Dialectto C++11and the C++ Standard Libraryto libc++ (LLVM C++ standard library with C++11 support)
假设您使用的是 Xcode,则不需要为 指定显式标志clang
或向 中添加构建路径/usr/include
,因为 IDE 已为您完成。您需要做的是打开项目设置 -> 构建设置并将C++ 语言方言设置为C++11,将C++ 标准库设置为libc++(支持 C++11 的 LLVM C++ 标准库)