Repository: pytorch
Issue: /usr/local/include/google/protobuf/stubs/pbconfig.h:3:37: note: expanded from macro 'GOOGLE_PROTOBUF_HASH_MAP_H'
Labels: module: build,triaged,module: macos

## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->
usr/local/include/google/protobuf/stubs/common.h:120:9: warning: 'GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION' macro redefined [-Wmacro-redefined]
#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3000000
        ^
../third_party/protobuf/src/google/protobuf/port_def.inc:307:9: note: previous definition is here
#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3011000
        ^
In file included from third_party/onnx/onnx/onnx-data_onnx_torch.pb.cc:4:
In file included from third_party/onnx/onnx/onnx-data_onnx_torch.pb.h:26:
In file included from ../third_party/protobuf/src/google/protobuf/generated_message_table_driven.h:34:
In file included from /usr/local/include/google/protobuf/map.h:35:
/usr/local/include/google/protobuf/stubs/hash.h:44:10: fatal error: 'tr1/unordered_map' file not found
#include GOOGLE_PROTOBUF_HASH_MAP_H
         ^
/usr/local/include/google/protobuf/stubs/pbconfig.h:3:37: note: expanded from macro 'GOOGLE_PROTOBUF_HASH_MAP_H'
 #define GOOGLE_PROTOBUF_HASH_MAP_H <tr1/unordered_map>
                                    ^~~~~~~~~~~~~~~~~~~
1 warning and 1 error generated.
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "setup.py", line 773, in <module>
    build_deps()
  File "setup.py", line 320, in build_deps
    cmake=cmake)
  File "/Users/davidlaxer/pytorch/tools/build_pytorch_libs.py", line 58, in build_caffe2
    cmake.build(my_env)
  File "/Users/davidlaxer/pytorch/tools/setup_helpers/cmake.py", line 345, in build
    self.run(build_args, my_env)
  File "/Users/davidlaxer/pytorch/tools/setup_helpers/cmake.py", line 140, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "/Users/davidlaxer/anaconda/envs/ai/lib/python3.6/subprocess.py", line 311, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '-j', '2']' returned non-zero exit status 1.

## To Reproduce

Steps to reproduce the behavior:

1. MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++  python setup.py install
1.
1.

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

<!-- A clear and concise description of what you expected to happen. -->


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.

## Environment

Please copy and paste the output from our
[environment collection script](https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py)
(or fill out the checklist below manually).

You can get the script and run it with:
```
wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
```
$ python collect_env.py
Collecting environment information...
PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: macOS 10.15.7 (x86_64)
GCC version: (MacPorts gcc10 10.2.0_4) 10.2.0
Clang version: Could not collect
CMake version: version 3.19.3

Python version: 3.6 (64-bit runtime)
Is CUDA available: N/A
CUDA runtime version: Could not collect
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.19.5
[pip3] torch==1.4.0
[conda] cpuonly                   1.0                           0    pytorch
[conda] nomkl                     3.0                           0  
[conda] numpy                     1.16.4                   pypi_0    pypi
[conda] torch                     1.4.0                    pypi_0    pypi

 - PyTorch Version (e.g., 1.0):
 - OS (e.g., Linux):
 - OS X 10.15.4 (Catalina
 - How you installed PyTorch (`conda`, `pip`, source):
 - conda
 - Build command you used (if compiling from source):
 - Python version:
 - CUDA/cuDNN version:
 - GPU models and configuration:
 - Any other relevant information:
https://stackoverflow.com/questions/42030598/mac-c-compiler-not-finding-tr1-unordered-map
## Additional context

<!-- Add any other context about the problem here. -->
I tried building pytorch with XCode 12.3 and 10.1.  Xcode 9 no longer runs on Catalina.


cc @malfet @seemethere @walterddr