gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:19:17 28 4
gpt4 key购买 nike

为什么这行不通:

#include <regex>
int main() {
return 0;
}

编译为:

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

如果我允许 stdliblibc++ 则它会编译。正则表达式是 c++11,但是 clang 似乎没有问题 -std=c++11 -stdlib=libstdc++ 本身。至少在我的机器上,看起来我可以在 /usr/include/regex.h 中使用某些东西,但这不是标准的,而且除了正则表达式之外我还想使用其他东西(例如 std::to_string)。

出现这种情况的原因是因为我想链接到第 3 方库(我没有源代码),它被编译为 std::string 而不是std::__1::basic_string,但我的代码使用了 std::regexstd::to_string。我不确定是否要引入对 boost 的依赖。

最佳答案

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

关于c++ - 如何获得 -std=c++11 w/libstdc++?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34729376/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com