Repository: pytorch
Issue: macOS error building 1.7.1 from source on Catalina 10.15.7
Labels: module: build,triaged,module: macos

## 🐛 Bug

`python setup.py develop` fails with this error:

>     -- Performing Test SUPPORT_GLIBCXX_USE_C99
>    -- Performing Test SUPPORT_GLIBCXX_USE_C99 - Failed
>    CMake Error at cmake/MiscCheck.cmake:81 (message):
>      The C++ compiler does not support required functions.  This is very likely
>      due to a known bug in GCC 5 (and maybe other versions) on Ubuntu 17.10 and
>      newer.  For more information, see:
>      https://github.com/pytorch/pytorch/issues/5229
>    Call Stack (most recent call first):
>      CMakeLists.txt:502 (include)

## To Reproduce

I'm building without Anaconda, and instead using python3's venv module. But I'm able to build that way on macOS Mojave 10.14.6 without any problem.

Steps to reproduce the behavior:

1. create environment: `/usr/bin/python3 -m venv venv`
2. `brew install cmake pkg-config libuv`
3. `source venv/bin/activate`
4. `pip install -U pip`
5. `pip install numpy ninja pyyaml mkl mkl-include setuptools cmake cffi typing_extensions future six requests dataclasses`
6. `export CMAKE_PREFIX_PATH=$VIRTUAL_ENV MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ USE_CUDA=0`
7. `pip install -e .`

Step 7 could also be `python setup.py install` or `python setup.py develop`. Those also fail.

(venv) smb % pip install -e .                                         
Obtaining file:///Users/smb/Work/GIT/pytorch
Requirement already satisfied: typing_extensions in ./venv/lib/python3.8/site-packages (from torch==1.7.0a0) (3.7.4.3)
Installing collected packages: torch
  Running setup.py develop for torch
    ERROR: Command errored out with exit status 1:
     command: /Users/smb/Work/GIT/pytorch/venv/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/Users/smb/Work/GIT/pytorch/setup.py'"'"'; __file__='"'"'/Users/smb/Work/GIT/pytorch/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps
         cwd: /Users/smb/Work/GIT/pytorch/
    Complete output (52 lines):
    -- The CXX compiler identification is AppleClang 11.0.0.11000033
    -- The C compiler identification is AppleClang 11.0.0.11000033
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Check for working CXX compiler: /Applications/Xcode_11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ - skipped
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working C compiler: /Applications/Xcode_11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - skipped
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Not forcing any particular BLAS to be found
    -- CLANG_VERSION_STRING:         Apple clang version 11.0.0 (clang-1100.0.33.17)
    Target: x86_64-apple-darwin19.6.0
    Thread model: posix
    InstalledDir: /Applications/Xcode_11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
    
    -- Performing Test COMPILER_WORKS
    -- Performing Test COMPILER_WORKS - Success
    -- Performing Test SUPPORT_GLIBCXX_USE_C99
    -- Performing Test SUPPORT_GLIBCXX_USE_C99 - Failed
    CMake Error at cmake/MiscCheck.cmake:81 (message):
      The C++ compiler does not support required functions.  This is very likely
      due to a known bug in GCC 5 (and maybe other versions) on Ubuntu 17.10 and
      newer.  For more information, see:
      https://github.com/pytorch/pytorch/issues/5229
    Call Stack (most recent call first):
      CMakeLists.txt:502 (include)
    
    
    -- Configuring incomplete, errors occurred!
    See also "/Users/smb/Work/GIT/pytorch/build/CMakeFiles/CMakeOutput.log".
    See also "/Users/smb/Work/GIT/pytorch/build/CMakeFiles/CMakeError.log".
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/Users/smb/Work/GIT/pytorch/setup.py", line 760, in <module>
        build_deps()
      File "/Users/smb/Work/GIT/pytorch/setup.py", line 310, in build_deps
        build_caffe2(version=version,
      File "/Users/smb/Work/GIT/pytorch/tools/build_pytorch_libs.py", line 54, in build_caffe2
        cmake.generate(version,
      File "/Users/smb/Work/GIT/pytorch/tools/setup_helpers/cmake.py", line 329, in generate
        self.run(args, env=my_env)
      File "/Users/smb/Work/GIT/pytorch/tools/setup_helpers/cmake.py", line 141, in run
        check_call(command, cwd=self.build_dir, env=env)
      File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/subprocess.py", line 364, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['cmake', '-GNinja', '-DBUILD_PYTHON=True', '-DBUILD_TEST=True', '-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_INSTALL_PREFIX=/Users/smb/Work/GIT/pytorch/torch', '-DCMAKE_PREFIX_PATH=/Users/smb/Work/GIT/pytorch/venv', '-DJAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/Current', '-DNUMPY_INCLUDE_DIR=/Users/smb/Work/GIT/pytorch/venv/lib/python3.8/site-packages/numpy/core/include', '-DPYTHON_EXECUTABLE=/Users/smb/Work/GIT/pytorch/venv/bin/python3', '-DPYTHON_INCLUDE_DIR=/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8', '-DPYTHON_LIBRARY=/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/Python3.framework/Versions/3.8/Python3', '-DTORCH_BUILD_VERSION=1.7.0a0', '-DUSE_CUDA=0', '-DUSE_NUMPY=True', '/Users/smb/Work/GIT/pytorch']' returned non-zero exit status 1.
    Building wheel torch-1.7.0a0
    -- Building version 1.7.0a0
    cmake -GNinja -DBUILD_PYTHON=True -DBUILD_TEST=True -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/Users/smb/Work/GIT/pytorch/torch -DCMAKE_PREFIX_PATH=/Users/smb/Work/GIT/pytorch/venv -DJAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/Current -DNUMPY_INCLUDE_DIR=/Users/smb/Work/GIT/pytorch/venv/lib/python3.8/site-packages/numpy/core/include -DPYTHON_EXECUTABLE=/Users/smb/Work/GIT/pytorch/venv/bin/python3 -DPYTHON_INCLUDE_DIR=/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8 -DPYTHON_LIBRARY=/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/Python3.framework/Versions/3.8/Python3 -DTORCH_BUILD_VERSION=1.7.0a0 -DUSE_CUDA=0 -DUSE_NUMPY=True /Users/smb/Work/GIT/pytorch
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/smb/Work/GIT/pytorch/venv/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/Users/smb/Work/GIT/pytorch/setup.py'"'"'; __file__='"'"'/Users/smb/Work/GIT/pytorch/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps Check the logs for full command output.


## Expected behavior

`setup.py develop` completes execution with the message `Successfully installed torch` 

## Environment

(venv) smb % 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: Could not collect
Clang version: 12.0.0 (clang-1200.0.32.29)
CMake version: version 3.18.4

Python version: 3.8 (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
[conda] Could not collect

## Additional context

PyTorch 1.7.1 builds fine on 10.14.6 Mojave with Xcode 11.3.1. I've tried installing Xcode 11.3.1 on Catalina and selecting it with xcode-select, but I get the same error.


cc @malfet @seemethere @walterddr