Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mac c++ compiler not finding <tr1/unordered_map>

Tags:

c++

macos

I guess the question of the day is "which" c++ compiler is the default on mac?

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

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

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

like image 634
AqC Avatar asked Feb 03 '17 18:02

AqC


1 Answers

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

Long answer: The reason for your error and the 2 sets of C++ includes is that macOS/Xcode has two different C++ standard libraries you can build against: an old GNU libstdc++, and the new and modern LLVM libc++.

As of macOS 10.12 Sierra, the default is now libc++ and libstdc++ is deprecated. libstdc++ is quite old, v4.2.1, and predates C++11 (hence the tr1 headers). If you're going to be using this code long-term, it'd be worth the time to at least make it C++11 compliant (i.e. #include <unordered_map>)

Update: Xcode 10 no longer allows building against libstdc++. Either update your codebase to use standard C++11 headers, or use Xcode 9 if that's really not an option.

like image 54
Brendan Shanks Avatar answered Oct 07 '22 01:10

Brendan Shanks