I'm on macOS Mojave 10.14.6 and I'm trying to compile some required extensions modules in c and c++ from this repository with:
python setup.py build_ext --inplace
which gives me the following error:
No CUDA runtime is found, using CUDA_HOME='/usr/local/cuda'
running build_ext
/Users/user/miniconda3/envs/torch/lib/python3.8/site-packages/torch/utils/cpp_extension.py:249: UserWarning: 
                               !! WARNING !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Your compiler (g++) is not compatible with the compiler Pytorch was
built with for this platform, which is clang++ on darwin. Please
use clang++ to to compile your extension. Alternatively, you may
compile PyTorch from source using g++, and then you can also use
g++ to compile your extension.
See https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md for help
with compiling PyTorch from source.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                              !! WARNING !!
  warnings.warn(WRONG_COMPILER_WARNING.format(
and further down:
clang: error: unknown argument: '-i'
clang: error: no such file or directory: 'sysroot'
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: error: unsupported option '-fopenmp'
ninja: build stopped: subcommand failed.
(this should be the relevant part, most recent tracebacks also show subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1. and finally RuntimeError: Error compiling objects for extension)
From what I understand and what I tried so far:
- the flag -fopenmpin the setup file is one of the problems, seems like OpenMP is missing
- thus I installed brew install llvmandbrew install libomp
- added PATH=\"/usr/local/bin:$PATH\to my.bash_profilehoping that the newly installed compilers are now used
- added the flag -Xpreprocessorbefore-fopenmpto the setup file according to here, so thatextra_compile_args=['-Xpreprocessor', '-std=c99', '-O3', '-fopenmp']
- I tried CC=gcc python setup.py build_ext --inplace, because of the warning about treating 'c' as 'c++' but since I'm trying to build c and c++ modules, I'm not sure what the variable should actually be set to
- I also tried CC=/usr/local/opt/llvm/bin/clang++ python setup.py build_ext --inplaceas suggested here
- trying to build this without -fopenmp(which is not actually an option, because I need the parallel execution which is provided by OpenMP IIRC) results basically in the same error without the error about OpenMP
- Do I also need to set CXXFLAGSandCFLAGS?
- now I'm doing all this inside a conda environment and it seems that Anaconda comes with their own tools. Should I be using those? and what are the required MacOSX SDK?
I'm sorry for this confusing question, but having no prior knowledge about compilers and trying to solve this is like going down the rabbit hole.... I would be very grateful for any comment shedding light on this situation and I'm happy to provide any missing information!
UPDATE:
- cleaning up the .bash_profileand exportingexport CC='gcc-10'; export CXX='clang++'got rid of the Pytorch warning, but clang problem remains
- still remains with os.environ['CC'] = 'gcc-10'andos.environ['CXX'] = 'clang++in thesetup.py
The complete error message is:
(torch) [10:48:05] vanessamac: occupancy_networks $ python setup.py build_ext --inplace --verbose
No CUDA runtime is found, using CUDA_HOME='/usr/local/cuda'
running build_ext
building 'im2mesh.utils.libkdtree.pykdtree.kdtree' extension
Emitting ninja build file /Users/vanessamac/projects/occupancy_networks/build/temp.macosx-10.9-x86_64-3.8/build.ninja...
Compiling objects...
Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)
[1/2] clang++ -MMD -MF '/Users/vanessamac/projects/occupancy_networks/build/temp.macosx-10.9-x86_64-3.8/im2mesh/utils/libkdtree/pykdtree/_kdtree_core.o'.d -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/vanessamac/miniconda3/envs/torch/include -arch x86_64 -I/Users/vanessamac/miniconda3/envs/torch/include -arch x86_64 -I/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/site-packages/numpy/core/include -I/Users/vanessamac/miniconda3/envs/torch/include/python3.8 -c -c '/Users/vanessamac/projects/occupancy_networks/im2mesh/utils/libkdtree/pykdtree/_kdtree_core.c' -o '/Users/vanessamac/projects/occupancy_networks/build/temp.macosx-10.9-x86_64-3.8/im2mesh/utils/libkdtree/pykdtree/_kdtree_core.o' -std=c99 -O3 -fopenmp -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=kdtree -D_GLIBCXX_USE_CXX11_ABI=0
FAILED: /Users/vanessamac/projects/occupancy_networks/build/temp.macosx-10.9-x86_64-3.8/im2mesh/utils/libkdtree/pykdtree/_kdtree_core.o 
clang++ -MMD -MF '/Users/vanessamac/projects/occupancy_networks/build/temp.macosx-10.9-x86_64-3.8/im2mesh/utils/libkdtree/pykdtree/_kdtree_core.o'.d -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/vanessamac/miniconda3/envs/torch/include -arch x86_64 -I/Users/vanessamac/miniconda3/envs/torch/include -arch x86_64 -I/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/site-packages/numpy/core/include -I/Users/vanessamac/miniconda3/envs/torch/include/python3.8 -c -c '/Users/vanessamac/projects/occupancy_networks/im2mesh/utils/libkdtree/pykdtree/_kdtree_core.c' -o '/Users/vanessamac/projects/occupancy_networks/build/temp.macosx-10.9-x86_64-3.8/im2mesh/utils/libkdtree/pykdtree/_kdtree_core.o' -std=c99 -O3 -fopenmp -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=kdtree -D_GLIBCXX_USE_CXX11_ABI=0
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: error: unsupported option '-fopenmp'
[2/2] clang++ -MMD -MF '/Users/vanessamac/projects/occupancy_networks/build/temp.macosx-10.9-x86_64-3.8/im2mesh/utils/libkdtree/pykdtree/kdtree.o'.d -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/vanessamac/miniconda3/envs/torch/include -arch x86_64 -I/Users/vanessamac/miniconda3/envs/torch/include -arch x86_64 -I/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/site-packages/numpy/core/include -I/Users/vanessamac/miniconda3/envs/torch/include/python3.8 -c -c '/Users/vanessamac/projects/occupancy_networks/im2mesh/utils/libkdtree/pykdtree/kdtree.c' -o '/Users/vanessamac/projects/occupancy_networks/build/temp.macosx-10.9-x86_64-3.8/im2mesh/utils/libkdtree/pykdtree/kdtree.o' -std=c99 -O3 -fopenmp -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=kdtree -D_GLIBCXX_USE_CXX11_ABI=0
FAILED: /Users/vanessamac/projects/occupancy_networks/build/temp.macosx-10.9-x86_64-3.8/im2mesh/utils/libkdtree/pykdtree/kdtree.o 
clang++ -MMD -MF '/Users/vanessamac/projects/occupancy_networks/build/temp.macosx-10.9-x86_64-3.8/im2mesh/utils/libkdtree/pykdtree/kdtree.o'.d -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/vanessamac/miniconda3/envs/torch/include -arch x86_64 -I/Users/vanessamac/miniconda3/envs/torch/include -arch x86_64 -I/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/site-packages/numpy/core/include -I/Users/vanessamac/miniconda3/envs/torch/include/python3.8 -c -c '/Users/vanessamac/projects/occupancy_networks/im2mesh/utils/libkdtree/pykdtree/kdtree.c' -o '/Users/vanessamac/projects/occupancy_networks/build/temp.macosx-10.9-x86_64-3.8/im2mesh/utils/libkdtree/pykdtree/kdtree.o' -std=c99 -O3 -fopenmp -DTORCH_API_INCLUDE_EXTENSION_H -DTORCH_EXTENSION_NAME=kdtree -D_GLIBCXX_USE_CXX11_ABI=0
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: error: unsupported option '-fopenmp'
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1509, in _run_ninja_build
    subprocess.run(
  File "/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "setup.py", line 112, in <module>
    setup(
  File "/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/site-packages/setuptools/__init__.py", line 165, in setup
    return distutils.core.setup(**attrs)
  File "/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/site-packages/setuptools/command/build_ext.py", line 87, in run
    _build_ext.run(self)
  File "/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/distutils/command/build_ext.py", line 340, in run
    self.build_extensions()
  File "/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 649, in build_extensions
    build_ext.build_extensions(self)
  File "/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/distutils/command/build_ext.py", line 449, in build_extensions
    self._build_extensions_serial()
  File "/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/distutils/command/build_ext.py", line 474, in _build_extensions_serial
    self.build_extension(ext)
  File "/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/site-packages/setuptools/command/build_ext.py", line 208, in build_extension
    _build_ext.build_extension(self, ext)
  File "/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/distutils/command/build_ext.py", line 528, in build_extension
    objects = self.compiler.compile(sources,
  File "/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 469, in unix_wrap_ninja_compile
    _write_ninja_file_and_compile_objects(
  File "/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1228, in _write_ninja_file_and_compile_objects
    _run_ninja_build(
  File "/Users/vanessamac/miniconda3/envs/torch/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 1529, in _run_ninja_build
    raise RuntimeError(message)
RuntimeError: Error compiling objects for extension
 
    