How to get -std = c ++ 11 w / libstdc ++?

Why this does not work:

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

Compiled as:

 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 

If I allow stdlib be libc++ , then it compiles. Regex c++11 , but clang doesn't seem to have a problem with both -std=c++11 -stdlib=libstdc++ per se. On my machine, at least it looks like what I can use in /usr/include/regex.h , but this is not standard, and there are also things other than the regular expression that I would like to use (e.g. std :: to_string).

The reason this happened is because I want to link a third-party library (for which I have no source) that matches std::string , not std::__1::basic_string , but my code uses std::regex and std::to_string . I'm not sure I want to imagine a dependency on the rise.

+5
source share
2 answers

Apple ships a very old version of libstdc ++ with OS X (I think 4.2.1). This version does not fully support C ++ 11, so you will need to use the newer version of std::regex .

+5
source

The version of libstdC ++ shipped with OS X comes from gcc-4.2.1, the latest version of GCC, before FSF decided to adopt GPL3. Apple abandoned libstdC ++ on OS X Lion in favor of libC ++ from the LLVM project. If you want to use C ++ 11 on OS X, you should use -std=c++11 -stdlib=libc++

+2
source

Source: https://habr.com/ru/post/1240378/


All Articles