'How to solve CompileError: command 'gcc' failed with exit status 1 while compiling?
I am trying to run "python build.py" by terminal on Ubuntu in a conda virtual env. But I got some below errors, you can see in the code! for your information:
The python version is 3.6!
Virtual environment created by conda!
You can see the main code of "build.py" here:
import os
import torch
#from torch.utils.ffi import create_extension
from torch.utils.cpp_extension import BuildExtension
sources = ['src/nms.c']
headers = ['src/nms.h']
defines = []
with_cuda = False
if torch.cuda.is_available():
print('Including CUDA code.')
sources += ['src/nms_cuda.c']
headers += ['src/nms_cuda.h']
defines += [('WITH_CUDA', None)]
with_cuda = True
this_file = os.path.dirname(os.path.realpath(__file__))
print(this_file)
extra_objects = ['src/cuda/nms_kernel.cu.o']
extra_objects = [os.path.join(this_file, fname) for fname in extra_objects]
#ffi = create_extension(
ffi=BuildExtension(
'_ext.nms',
headers=headers,
sources=sources,
define_macros=defines,
relative_to=__file__,
with_cuda=with_cuda,
extra_objects=extra_objects
)
if __name__ == '__main__':
ffi.build()
Here you can see a brief of errors I received after execution!
(env)$ python build.py
Traceback (most recent call last):
File "/home/username/anaconda3/envs/deep9/lib/python3.6/distutils/unixccompiler.py", line 118, in _compile
extra_postargs)
File "/home/username/anaconda3/envs/deep9/lib/python3.6/distutils/ccompiler.py", line 909, in spawn
spawn(cmd, dry_run=self.dry_run)
File "/home/username/anaconda3/envs/deep9/lib/python3.6/distutils/spawn.py", line 36, in spawn
_spawn_posix(cmd, search_path, dry_run=dry_run)
File "/home/username/anaconda3/envs/deep9/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix
% (cmd, exit_status))
distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/username/anaconda3/envs/deep9/lib/python3.6/site-packages/cffi/ffiplatform.py", line 51, in _build
dist.run_command('build_ext')
File "/home/username/anaconda3/envs/deep9/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/home/username/anaconda3/envs/deep9/lib/python3.6/distutils/command/build_ext.py", line 339, in run
self.build_extensions()
File "/home/username/anaconda3/envs/deep9/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions
self._build_extensions_serial()
File "/home/username/anaconda3/envs/deep9/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial
self.build_extension(ext)
File "/home/username/anaconda3/envs/deep9/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension
depends=ext.depends)
File "/home/username/anaconda3/envs/deep9/lib/python3.6/distutils/ccompiler.py", line 574, in compile
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
File "/home/username/anaconda3/envs/deep9/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile
raise CompileError(msg)
distutils.errors.CompileError: command 'gcc' failed with exit status 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "build.py", line 34, in <module>
ffi.build()
File "/home/username/anaconda3/envs/deep9/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 184, in build
_build_extension(ffi, cffi_wrapper_name, target_dir, verbose)
File "/home/username/anaconda3/envs/deep9/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 108, in _build_extension
outfile = ffi.compile(tmpdir=tmpdir, verbose=verbose, target=libname)
File "/home/username/anaconda3/envs/deep9/lib/python3.6/site-packages/cffi/api.py", line 727, in compile
compiler_verbose=verbose, debug=debug, **kwds)
File "/home/username/anaconda3/envs/deep9/lib/python3.6/site-packages/cffi/recompiler.py", line 1565, in recompile
compiler_verbose, debug)
File "/home/username/anaconda3/envs/deep9/lib/python3.6/site-packages/cffi/ffiplatform.py", line 22, in compile
outputfilename = _build(tmpdir, ext, compiler_verbose, debug)
File "/home/username/anaconda3/envs/deep9/lib/python3.6/site-packages/cffi/ffiplatform.py", line 58, in _build
raise VerificationError('%s: %s' % (e.__class__.__name__, e))
cffi.VerificationError: CompileError: command 'gcc' failed with exit status 1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
