Repository: pytorch
Issue: [custom op]RuntimeError: Error compiling objects for extension
Labels: module: build,module: cpp-extensions,triaged

## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->

I am trying to implement an operator  according to [EXTENDING TORCHSCRIPT WITH CUSTOM C++ OPERATORS](https://pytorch.org/tutorials/advanced/torch_script_custom_ops.html)

when run `python set_up.py install`  to compile it, error as the following
```
running install
running bdist_egg
running egg_info
creating warp_perspective.egg-info
writing warp_perspective.egg-info/PKG-INFO
writing dependency_links to warp_perspective.egg-info/dependency_links.txt
writing top-level names to warp_perspective.egg-info/top_level.txt
writing manifest file 'warp_perspective.egg-info/SOURCES.txt'
reading manifest file 'warp_perspective.egg-info/SOURCES.txt'
writing manifest file 'warp_perspective.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_ext
building 'warp_perspective' extension
creating  /warp-perspective/build/temp.linux-x86_64-3.7
creating /warp-perspective/build/temp.linux-x86_64-3.7/example_app
creating /warp-perspective/build/temp.linux-x86_64-3.7/example_app/warp_perspective
anaconda3/envs/torch/lib/python3.7/site-packages/torch/utils/cpp_extension.py:287: UserWarning: 

                               !! WARNING !!

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Your compiler (c++) is not compatible with the compiler Pytorch was
built with for this platform, which is g++ on linux. Please
use g++ to to compile your extension. Alternatively, you may
compile PyTorch from source using c++, and then you can also use
c++ to compile your extension.

See https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md for help
with compiling PyTorch from source.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

                              !! WARNING !!

  platform=sys.platform))
Emitting ninja build file /warp-perspective/build/temp.linux-x86_64-3.7/build.ninja...
Compiling objects...
Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)
ninja: error: '/warp-perspective/example_app/warp_perspective/op.cpp', needed by '/warp-perspective/build/temp.linux-x86_64-3.7/example_app/warp_perspective/op.o', missing and no known rule to make it
Traceback (most recent call last):
  File "/anaconda3/envs/torch/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1672, in _run_ninja_build
    env=env)
  File "/anaconda3/envs/torch/lib/python3.7/subprocess.py", line 512, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "setup.py", line 13, in <module>
    cmdclass={"build_ext": BuildExtension.with_options(no_python_abi_suffix=True)},
  File "/anaconda3/envs/torch/lib/python3.7/site-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "anaconda3/envs/torch/lib/python3.7/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/anaconda3/envs/torch/lib/python3.7/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/anaconda3/envs/torch/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/anaconda3/envs/torch/lib/python3.7/site-packages/setuptools/command/install.py", line 67, in run
    self.do_egg_install()
  File "anaconda3/envs/torch/lib/python3.7/site-packages/setuptools/command/install.py", line 109, in do_egg_install
    self.run_command('bdist_egg')
  File "anaconda3/envs/torch/lib/python3.7/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/anaconda3/envs/torch/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/anaconda3/envs/torch/lib/python3.7/site-packages/setuptools/command/bdist_egg.py", line 164, in run
    cmd = self.call_command('install_lib', warn_dir=0)
  File "/anaconda3/envs/torch/lib/python3.7/site-packages/setuptools/command/bdist_egg.py", line 150, in call_command
    self.run_command(cmdname)
  File "/anaconda3/envs/torch/lib/python3.7/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "anaconda3/envs/torch/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/anaconda3/envs/torch/lib/python3.7/site-packages/setuptools/command/install_lib.py", line 11, in run
    self.build()
  File "/anaconda3/envs/torch/lib/python3.7/distutils/command/install_lib.py", line 107, in build
    self.run_command('build_ext')
  File "/anaconda3/envs/torch/lib/python3.7/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/anaconda3/envs/torch/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/anaconda3/envs/torch/lib/python3.7/site-packages/setuptools/command/build_ext.py", line 79, in run
    _build_ext.run(self)
  File "/anaconda3/envs/torch/lib/python3.7/distutils/command/build_ext.py", line 340, in run
    self.build_extensions()
  File "/anaconda3/envs/torch/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 709, in build_extensions
    build_ext.build_extensions(self)
  File "/anaconda3/envs/torch/lib/python3.7/distutils/command/build_ext.py", line 449, in build_extensions
    self._build_extensions_serial()
  File "/anaconda3/envs/torch/lib/python3.7/distutils/command/build_ext.py", line 474, in _build_extensions_serial
    self.build_extension(ext)
  File "anaconda3/envs/torch/lib/python3.7/site-packages/setuptools/command/build_ext.py", line 196, in build_extension
    _build_ext.build_extension(self, ext)
  File "/anaconda3/envs/torch/lib/python3.7/distutils/command/build_ext.py", line 534, in build_extension
    depends=ext.depends)
  File "/anaconda3/envs/torch/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 539, in unix_wrap_ninja_compile
    with_cuda=with_cuda)
  File "/anaconda3/envs/torch/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1360, in _write_ninja_file_and_compile_objects
    error_prefix='Error compiling objects for extension')
  File "/anaconda3/envs/torch/lib/python3.7/site-packages/torch/utils/cpp_extension.py", line 1682, in _run_ninja_build
    raise RuntimeError(message) from e
RuntimeError: Error compiling objects for extension

```

## To Reproduce

Steps to reproduce the behavior:

1.
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. -->

## 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
```

 - PyTorch Version (e.g., 1.0): 1.9.0
 - OS (e.g., Linux):
 - How you installed PyTorch (`conda`, `pip`, source):conda
 - Build command you used (if compiling from source):
 - Python version: 3.7.10
 - CUDA/cuDNN version:
 - GPU models and configuration:
 - Any other relevant information:

## Additional context

<!-- Add any other context about the problem here. -->


cc @malfet @seemethere @walterddr @yf225 @glaringlee @zou3519