如何获得-std = c ++ 11 w/libstdc ++?

amo*_*mos 5 c++ clang libstdc++ c++11 libc++

为什么这不起作用:

#include <regex>
int main() {
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译为:

clang++ -std=c++11 -stdlib=libstdc++ temp.cpp
temp.cpp:1:10: fatal error: 'regex' file not found
#include <regex>
         ^
1 error generated.


clang++ --version
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
Run Code Online (Sandbox Code Playgroud)

如果我能够stdlib成为libc++然后再编译.正则表达式c++11,但clang本身似乎没有问题-std=c++11 -stdlib=libstdc++.至少在我的机器上,它看起来像我可以使用的东西/usr/include/regex.h,但这不是标准的,除了我想使用的正则表达式以外的东西(例如std :: to_string).

这已经想出的原因是因为我想链接到第三方库(对此我没有源),这是符合作为std::string,而不是std::__1::basic_string,但我代码使用std::regexstd::to_string.我不确定是否要引入对boost的依赖.

Mil*_*nek 5

Apple发布了一个非常旧版本的libstdc ++和OS X(我认为是4.2.1).该版本并不完全支持C++ 11,因此您需要使用更新的版本std::regex.