Mac C ++ compiler does not find <tr1 / unordered_map>

I think the question of the day is โ€œwhatโ€ C ++ compiler is the default for mac?

If I do xcrun -find c++ , it says this in /Applications/Xcode.app/etc...

When I search the Xcode directory for tr1/unordered_map , it is there.

So I'm confused. Why am I getting a build error that says fatal error: 'tr1/unordered_map' file not found ?

+7
source share
1 answer

Short answer: call clang ++ with -stdlib=libstdc++ and the tr1 headers will be there.

Long answer: the reason for your mistake and two sets of C ++ is that macOS / Xcode has two different standard C ++ libraries that you can create: the old GNU libstdc++ and the new modern LLVM libC++ .

Starting with macOS 10.12 Sierra, libC++ now used by default and libstdc++ deprecated. libstdc++ pretty old, v4.2.1, and precedes C ++ 11 (hence the tr1 headers). If you intend to use this code in the long run, it is worth the time to at least make it compatible with C ++ 11 (i.e. #include <unordered_map> )

Update : Xcode 10 no longer allows building against libstdc ++. Either upgrade your codebase to use the standard C ++ 11 headers, or use Xcode 9 if this is really not an option.

+19
source

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


All Articles