文章目录

  • 1. 问题描述
    • 1.1 构建的环境:完全按照要求
    • 1.2 编译出错的具体情况
      • 1.2.1 编译make.sh前必要的修改
      • 1.2.2 报错信息
  • 2.解决方法
    • 2.1 我的解决方法
    • 2.2 总结

1. 问题描述

本人在编译Few-Shot Object Detection with Attention-RPN and Multi-Relation Detector一文的开源代码https://github.com/fanq15/FSOD-code时遇到了报错:
......lib/include/THC/THCGeneral.h:12:18:fatal error: cuda.h: No such file or directory

1.1 构建的环境:完全按照要求

pytorch0.4.1
torchvision>=0.2.0
cython
matplotlib
numpy
scipy
opencv
pyyaml3.12
packaging
pandas
pycocotools
CUDA=9.0

  1. 本人使用实验室公用的工作站,所以我不能把CUDA9.0安装在usr/local/下(以免影响他人使用特定版本的CUDA),只能安装在我的/home目录下:
    CUDA一般的安装位置:/usr/local/cuda-9.0/
    我的CUDA安装位置:/home/hongze/cudas/cuda-9.0/
  2. 安装多个CUDA之后一定要查看nvcc的版本:
(base) hongze@lab-PowerEdge-T630 ~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176
  1. 如果版本不是需要的版本,需要在.bashrc文件更改,例如我安装了两个版本的CUDA:
(base) hongze@lab-PowerEdge-T630 ~/cudas$ ls
cuda-10.1  cuda9  include  lib64  NVIDIA_CUDA-10.1_Samples  NVIDIA_CUDA-9.0_Samples  src
  1. 我通过更改.bashrc文件中这三行来决定我启用哪个版本的CUDA(我没有使用软连接,而是直接指向了真实的目录位置;如果使用软连接则需要更改软连接来实现:查看这条博客)

#我的.bashrc的更改之前的关键三行:
#把cuda-9.0改成cuda-10.0,然后source一下.bashrc文件,将终端关闭重新打开,再查看nvcc版本,就变成了10.0export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/hongze/cudas/cuda-9.0/lib64
export PATH=$PATH:/home/hongze/cudas/cuda-9.0/bin
export CUDA_HOME=$CUDA_HOME:/home/hongze/cudas/cuda-9.0

1.2 编译出错的具体情况

1.2.1 编译make.sh前必要的修改

  • 基本上make.sh编译前需要检查CUDA_ARCH是否与你的显卡适配:详情看这个博客或者nvidia官网的信息;
  • 如果你的CUDA的软连接无效了或者像我一样不使用软链接,则需要修改CUDA_PATH;
#make.sh文件的内容
#!/usr/bin/env bash#CUDA_PATH=/usr/local/cuda/
CUDA_PATH=/home/hongze/cudas/cuda9#我修改了我的CUDA_PATHexport CXXFLAGS="-std=c++11"
export CFLAGS="-std=c99"python3 setup.py build_ext --inplace
rm -rf build# Choose cuda arch as you need
CUDA_ARCH="-gencode arch=compute_30,code=sm_30 \-gencode arch=compute_35,code=sm_35 \-gencode arch=compute_50,code=sm_50 \-gencode arch=compute_52,code=sm_52 \-gencode arch=compute_60,code=sm_60 \-gencode arch=compute_61,code=sm_61 \-gencode arch=compute_70,code=sm_70 "#我使用的显卡是TITAN XP# compile NMS
cd model/nms/src
echo "Compiling nms kernels by nvcc..."
nvcc -c -o nms_cuda_kernel.cu.o nms_cuda_kernel.cu \-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCHcd ../
python3 build.py# compile roi_pooling
cd ../../
cd model/roi_pooling/src
echo "Compiling roi pooling kernels by nvcc..."
nvcc -c -o roi_pooling.cu.o roi_pooling_kernel.cu \-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
cd ../
python3 build.py# # compile roi_align
# cd ../../
# cd model/roi_align/src
# echo "Compiling roi align kernels by nvcc..."
# nvcc -c -o roi_align_kernel.cu.o roi_align_kernel.cu \
#    -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
# cd ../
# python3 build.p# compile roi_crop
cd ../../
cd model/roi_crop/src
echo "Compiling roi crop kernels by nvcc..."
nvcc -c -o roi_crop_cuda_kernel.cu.o roi_crop_cuda_kernel.cu \-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
cd ../
python3 build.py# compile roi_align (based on Caffe2's implementation)
cd ../../
cd modeling/roi_xfrom/roi_align/src
echo "Compiling roi align kernels by nvcc..."
nvcc -c -o roi_align_kernel.cu.o roi_align_kernel.cu \-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
cd ../
python3 build.py

1.2.2 报错信息

fatal error: cuda.h: No such file or directory一共出现4次,分别是编译NMS、roi_pooling、roi_crop、roi_align四个部分产生的

#执行sh make.sh的报错信息
(FSOD) hongze@lab-PowerEdge-T630 ~/Documents/FSOD-code/lib$ sh make.sh
running build_ext
building 'utils.cython_bbox' extension
creating build
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/utils
gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/numpy/core/include -I/home/hongze/anaconda3/envs/FSOD/include/python3.6m -c utils/cython_bbox.c -o build/temp.linux-x86_64-3.6/utils/cython_bbox.o -Wno-cpp
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/utils
c99 build/temp.linux-x86_64-3.6/utils/cython_bbox.o -L/home/hongze/anaconda3/envs/FSOD/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/utils/cython_bbox.cpython-36m-x86_64-linux-gnu.so
building 'utils.cython_nms' extension
gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/numpy/core/include -I/home/hongze/anaconda3/envs/FSOD/include/python3.6m -c utils/cython_nms.c -o build/temp.linux-x86_64-3.6/utils/cython_nms.o -Wno-cpp
gcc -pthread -shared -L/home/hongze/anaconda3/envs/FSOD/lib -Wl,-rpath=/home/hongze/anaconda3/envs/FSOD/lib,--no-as-needed -std=c99 build/temp.linux-x86_64-3.6/utils/cython_nms.o -L/home/hongze/anaconda3/envs/FSOD/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/utils/cython_nms.cpython-36m-x86_64-linux-gnu.so
copying build/lib.linux-x86_64-3.6/utils/cython_bbox.cpython-36m-x86_64-linux-gnu.so -> utils
copying build/lib.linux-x86_64-3.6/utils/cython_nms.cpython-36m-x86_64-linux-gnu.so -> utils
Compiling nms kernels by nvcc...
Including CUDA code.
/home/hongze/Documents/FSOD-code/lib/model/nms
['/home/hongze/Documents/FSOD-code/lib/model/nms/src/nms_cuda_kernel.cu.o']
generating /tmp/tmp5qy32gtx/_nms.c
setting the current directory to '/tmp/tmp5qy32gtx'
running build_ext
building '_nms' extension
creating home
creating home/hongze
creating home/hongze/Documents
creating home/hongze/Documents/FSOD-code
creating home/hongze/Documents/FSOD-code/lib
creating home/hongze/Documents/FSOD-code/lib/model
creating home/hongze/Documents/FSOD-code/lib/model/nms
creating home/hongze/Documents/FSOD-code/lib/model/nms/src
gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/home/hongze/anaconda3/envs/FSOD/include/python3.6m -c _nms.c -o ./_nms.o -std=c99
In file included from /home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC/THC.h:4:0,from _nms.c:570:
/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC/THCGeneral.h:12:18: fatal error: cuda.h: No such file or directory
compilation terminated.
Traceback (most recent call last):File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/unixccompiler.py", line 118, in _compileextra_postargs)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/ccompiler.py", line 909, in spawnspawn(cmd, dry_run=self.dry_run)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/spawn.py", line 36, in spawn_spawn_posix(cmd, search_path, dry_run=dry_run)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix% (cmd, exit_status))
distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1During handling of the above exception, another exception occurred:Traceback (most recent call last):File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/ffiplatform.py", line 51, in _builddist.run_command('build_ext')File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/dist.py", line 974, in run_commandcmd_obj.run()File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/command/build_ext.py", line 339, in runself.build_extensions()File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensionsself._build_extensions_serial()File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serialself.build_extension(ext)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extensiondepends=ext.depends)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/ccompiler.py", line 574, in compileself._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/unixccompiler.py", line 120, in _compileraise CompileError(msg)
distutils.errors.CompileError: command 'gcc' failed with exit status 1During handling of the above exception, another exception occurred:Traceback (most recent call last):File "build.py", line 37, in <module>ffi.build()File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 189, in build_build_extension(ffi, cffi_wrapper_name, target_dir, verbose)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 111, in _build_extensionoutfile = ffi.compile(tmpdir=tmpdir, verbose=verbose, target=libname)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/api.py", line 727, in compilecompiler_verbose=verbose, debug=debug, **kwds)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/recompiler.py", line 1555, in recompilecompiler_verbose, debug)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/ffiplatform.py", line 22, in compileoutputfilename = _build(tmpdir, ext, compiler_verbose, debug)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/ffiplatform.py", line 58, in _buildraise VerificationError('%s: %s' % (e.__class__.__name__, e))
cffi.VerificationError: CompileError: command 'gcc' failed with exit status 1
Compiling roi pooling kernels by nvcc...
Including CUDA code.
/home/hongze/Documents/FSOD-code/lib/model/roi_pooling
generating /tmp/tmpuhxsnvnf/_roi_pooling.c
setting the current directory to '/tmp/tmpuhxsnvnf'
running build_ext
building '_roi_pooling' extension
creating home
creating home/hongze
creating home/hongze/Documents
creating home/hongze/Documents/FSOD-code
creating home/hongze/Documents/FSOD-code/lib
creating home/hongze/Documents/FSOD-code/lib/model
creating home/hongze/Documents/FSOD-code/lib/model/roi_pooling
creating home/hongze/Documents/FSOD-code/lib/model/roi_pooling/src
gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/home/hongze/anaconda3/envs/FSOD/include/python3.6m -c _roi_pooling.c -o ./_roi_pooling.o -std=c99
In file included from /home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC/THC.h:4:0,from _roi_pooling.c:570:
/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC/THCGeneral.h:12:18: fatal error: cuda.h: No such file or directory
compilation terminated.
Traceback (most recent call last):File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/unixccompiler.py", line 118, in _compileextra_postargs)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/ccompiler.py", line 909, in spawnspawn(cmd, dry_run=self.dry_run)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/spawn.py", line 36, in spawn_spawn_posix(cmd, search_path, dry_run=dry_run)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix% (cmd, exit_status))
distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1During handling of the above exception, another exception occurred:Traceback (most recent call last):File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/ffiplatform.py", line 51, in _builddist.run_command('build_ext')File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/dist.py", line 974, in run_commandcmd_obj.run()File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/command/build_ext.py", line 339, in runself.build_extensions()File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensionsself._build_extensions_serial()File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serialself.build_extension(ext)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extensiondepends=ext.depends)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/ccompiler.py", line 574, in compileself._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/unixccompiler.py", line 120, in _compileraise CompileError(msg)
distutils.errors.CompileError: command 'gcc' failed with exit status 1During handling of the above exception, another exception occurred:Traceback (most recent call last):File "build.py", line 35, in <module>ffi.build()File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 189, in build_build_extension(ffi, cffi_wrapper_name, target_dir, verbose)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 111, in _build_extensionoutfile = ffi.compile(tmpdir=tmpdir, verbose=verbose, target=libname)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/api.py", line 727, in compilecompiler_verbose=verbose, debug=debug, **kwds)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/recompiler.py", line 1555, in recompilecompiler_verbose, debug)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/ffiplatform.py", line 22, in compileoutputfilename = _build(tmpdir, ext, compiler_verbose, debug)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/ffiplatform.py", line 58, in _buildraise VerificationError('%s: %s' % (e.__class__.__name__, e))
cffi.VerificationError: CompileError: command 'gcc' failed with exit status 1
Compiling roi crop kernels by nvcc...
Including CUDA code.
/home/hongze/Documents/FSOD-code/lib/model/roi_crop
generating /tmp/tmp3j3suxnv/_roi_crop.c
setting the current directory to '/tmp/tmp3j3suxnv'
running build_ext
building '_roi_crop' extension
creating home
creating home/hongze
creating home/hongze/Documents
creating home/hongze/Documents/FSOD-code
creating home/hongze/Documents/FSOD-code/lib
creating home/hongze/Documents/FSOD-code/lib/model
creating home/hongze/Documents/FSOD-code/lib/model/roi_crop
creating home/hongze/Documents/FSOD-code/lib/model/roi_crop/src
gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/home/hongze/anaconda3/envs/FSOD/include/python3.6m -c _roi_crop.c -o ./_roi_crop.o -std=c99
In file included from /home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC/THC.h:4:0,from _roi_crop.c:570:
/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC/THCGeneral.h:12:18: fatal error: cuda.h: No such file or directory
compilation terminated.
Traceback (most recent call last):File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/unixccompiler.py", line 118, in _compileextra_postargs)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/ccompiler.py", line 909, in spawnspawn(cmd, dry_run=self.dry_run)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/spawn.py", line 36, in spawn_spawn_posix(cmd, search_path, dry_run=dry_run)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix% (cmd, exit_status))
distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1During handling of the above exception, another exception occurred:Traceback (most recent call last):File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/ffiplatform.py", line 51, in _builddist.run_command('build_ext')File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/dist.py", line 974, in run_commandcmd_obj.run()File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/command/build_ext.py", line 339, in runself.build_extensions()File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensionsself._build_extensions_serial()File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serialself.build_extension(ext)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extensiondepends=ext.depends)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/ccompiler.py", line 574, in compileself._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/unixccompiler.py", line 120, in _compileraise CompileError(msg)
distutils.errors.CompileError: command 'gcc' failed with exit status 1During handling of the above exception, another exception occurred:Traceback (most recent call last):File "build.py", line 36, in <module>ffi.build()File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 189, in build_build_extension(ffi, cffi_wrapper_name, target_dir, verbose)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 111, in _build_extensionoutfile = ffi.compile(tmpdir=tmpdir, verbose=verbose, target=libname)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/api.py", line 727, in compilecompiler_verbose=verbose, debug=debug, **kwds)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/recompiler.py", line 1555, in recompilecompiler_verbose, debug)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/ffiplatform.py", line 22, in compileoutputfilename = _build(tmpdir, ext, compiler_verbose, debug)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/ffiplatform.py", line 58, in _buildraise VerificationError('%s: %s' % (e.__class__.__name__, e))
cffi.VerificationError: CompileError: command 'gcc' failed with exit status 1
Compiling roi align kernels by nvcc...
Including CUDA code.
/home/hongze/Documents/FSOD-code/lib/modeling/roi_xfrom/roi_align
generating /tmp/tmpfskoao8a/_roi_align.c
setting the current directory to '/tmp/tmpfskoao8a'
running build_ext
building '_roi_align' extension
creating home
creating home/hongze
creating home/hongze/Documents
creating home/hongze/Documents/FSOD-code
creating home/hongze/Documents/FSOD-code/lib
creating home/hongze/Documents/FSOD-code/lib/modeling
creating home/hongze/Documents/FSOD-code/lib/modeling/roi_xfrom
creating home/hongze/Documents/FSOD-code/lib/modeling/roi_xfrom/roi_align
creating home/hongze/Documents/FSOD-code/lib/modeling/roi_xfrom/roi_align/src
gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/home/hongze/anaconda3/envs/FSOD/include/python3.6m -c _roi_align.c -o ./_roi_align.o -std=c99
In file included from /home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC/THC.h:4:0,from _roi_align.c:570:
/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC/THCGeneral.h:12:18: fatal error: cuda.h: No such file or directory
compilation terminated.
Traceback (most recent call last):File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/unixccompiler.py", line 118, in _compileextra_postargs)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/ccompiler.py", line 909, in spawnspawn(cmd, dry_run=self.dry_run)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/spawn.py", line 36, in spawn_spawn_posix(cmd, search_path, dry_run=dry_run)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix% (cmd, exit_status))
distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1During handling of the above exception, another exception occurred:Traceback (most recent call last):File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/ffiplatform.py", line 51, in _builddist.run_command('build_ext')File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/dist.py", line 974, in run_commandcmd_obj.run()File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/command/build_ext.py", line 339, in runself.build_extensions()File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensionsself._build_extensions_serial()File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serialself.build_extension(ext)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extensiondepends=ext.depends)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/ccompiler.py", line 574, in compileself._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/distutils/unixccompiler.py", line 120, in _compileraise CompileError(msg)
distutils.errors.CompileError: command 'gcc' failed with exit status 1During handling of the above exception, another exception occurred:Traceback (most recent call last):File "build.py", line 36, in <module>ffi.build()File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 189, in build_build_extension(ffi, cffi_wrapper_name, target_dir, verbose)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 111, in _build_extensionoutfile = ffi.compile(tmpdir=tmpdir, verbose=verbose, target=libname)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/api.py", line 727, in compilecompiler_verbose=verbose, debug=debug, **kwds)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/recompiler.py", line 1555, in recompilecompiler_verbose, debug)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/ffiplatform.py", line 22, in compileoutputfilename = _build(tmpdir, ext, compiler_verbose, debug)File "/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/cffi/ffiplatform.py", line 58, in _buildraise VerificationError('%s: %s' % (e.__class__.__name__, e))
cffi.VerificationError: CompileError: command 'gcc' failed with exit status 1

2.解决方法

主要要修改的有两个地方:make.sh文件的内容、执行make.sh的命令

2.1 我的解决方法

参考了这条回答:看原出处

Hi all, if you encounter this error on compling fatal error: cuda.h: No such file or directory
Try this:
CPATH=/path/to/you/cuda/include ./make.sh

于是我编译时输入的命令由:sh make.sh改为CPATH=/home/hongze/cudas/cuda9/include/ ./make.sh,编译成功

#编译成功的结果
(FSOD) hongze@lab-PowerEdge-T630 ~/Documents/FSOD-code/lib$ CPATH=/home/hongze/cudas/cuda9/include/ ./make.sh
running build_ext
building 'utils.cython_bbox' extension
creating build
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/utils
gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/numpy/core/include -I/home/hongze/anaconda3/envs/FSOD/include/python3.6m -c utils/cython_bbox.c -o build/temp.linux-x86_64-3.6/utils/cython_bbox.o -Wno-cpp
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/utils
gcc -pthread -shared -L/home/hongze/anaconda3/envs/FSOD/lib -Wl,-rpath=/home/hongze/anaconda3/envs/FSOD/lib,--no-as-needed build/temp.linux-x86_64-3.6/utils/cython_bbox.o -L/home/hongze/anaconda3/envs/FSOD/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/utils/cython_bbox.cpython-36m-x86_64-linux-gnu.so
building 'utils.cython_nms' extension
gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/numpy/core/include -I/home/hongze/anaconda3/envs/FSOD/include/python3.6m -c utils/cython_nms.c -o build/temp.linux-x86_64-3.6/utils/cython_nms.o -Wno-cpp
utils/cython_nms.c: In function ‘__pyx_pf_5utils_10cython_nms_2soft_nms’:
utils/cython_nms.c:3399:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]__pyx_t_10 = ((__pyx_v_pos < __pyx_v_N) != 0);^
utils/cython_nms.c:3910:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]__pyx_t_10 = ((__pyx_v_pos < __pyx_v_N) != 0);^
gcc -pthread -shared -L/home/hongze/anaconda3/envs/FSOD/lib -Wl,-rpath=/home/hongze/anaconda3/envs/FSOD/lib,--no-as-needed build/temp.linux-x86_64-3.6/utils/cython_nms.o -L/home/hongze/anaconda3/envs/FSOD/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/utils/cython_nms.cpython-36m-x86_64-linux-gnu.so
copying build/lib.linux-x86_64-3.6/utils/cython_bbox.cpython-36m-x86_64-linux-gnu.so -> utils
copying build/lib.linux-x86_64-3.6/utils/cython_nms.cpython-36m-x86_64-linux-gnu.so -> utils
running build_ext
building 'utils.cython_bbox' extension
creating build
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/utils
gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/numpy/core/include -I/home/hongze/anaconda3/envs/FSOD/include/python3.6m -c utils/cython_bbox.c -o build/temp.linux-x86_64-3.6/utils/cython_bbox.o -Wno-cpp
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/utils
gcc -pthread -shared -L/home/hongze/anaconda3/envs/FSOD/lib -Wl,-rpath=/home/hongze/anaconda3/envs/FSOD/lib,--no-as-needed -std=c99 build/temp.linux-x86_64-3.6/utils/cython_bbox.o -L/home/hongze/anaconda3/envs/FSOD/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/utils/cython_bbox.cpython-36m-x86_64-linux-gnu.so
building 'utils.cython_nms' extension
gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/numpy/core/include -I/home/hongze/anaconda3/envs/FSOD/include/python3.6m -c utils/cython_nms.c -o build/temp.linux-x86_64-3.6/utils/cython_nms.o -Wno-cpp
gcc -pthread -shared -L/home/hongze/anaconda3/envs/FSOD/lib -Wl,-rpath=/home/hongze/anaconda3/envs/FSOD/lib,--no-as-needed -std=c99 build/temp.linux-x86_64-3.6/utils/cython_nms.o -L/home/hongze/anaconda3/envs/FSOD/lib -lpython3.6m -o build/lib.linux-x86_64-3.6/utils/cython_nms.cpython-36m-x86_64-linux-gnu.so
copying build/lib.linux-x86_64-3.6/utils/cython_bbox.cpython-36m-x86_64-linux-gnu.so -> utils
copying build/lib.linux-x86_64-3.6/utils/cython_nms.cpython-36m-x86_64-linux-gnu.so -> utils
Compiling nms kernels by nvcc...
Including CUDA code.
/home/hongze/Documents/FSOD-code/lib/model/nms
['/home/hongze/Documents/FSOD-code/lib/model/nms/src/nms_cuda_kernel.cu.o']
generating /tmp/tmpw5rm8jqh/_nms.c
setting the current directory to '/tmp/tmpw5rm8jqh'
running build_ext
building '_nms' extension
creating home
creating home/hongze
creating home/hongze/Documents
creating home/hongze/Documents/FSOD-code
creating home/hongze/Documents/FSOD-code/lib
creating home/hongze/Documents/FSOD-code/lib/model
creating home/hongze/Documents/FSOD-code/lib/model/nms
creating home/hongze/Documents/FSOD-code/lib/model/nms/src
gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/home/hongze/anaconda3/envs/FSOD/include/python3.6m -c _nms.c -o ./_nms.o -std=c99
gcc -pthread -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=c99 -fPIC -DWITH_CUDA -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/home/hongze/anaconda3/envs/FSOD/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/home/hongze/anaconda3/envs/FSOD/include/python3.6m -c /home/hongze/Documents/FSOD-code/lib/model/nms/src/nms_cuda.c -o ./home/hongze/Documents/FSOD-code/lib/model/nms/src/nms_cuda.o -std=c99
gcc -pthread -shared -L/home/hongze/anaconda3/envs/FSOD/lib -Wl,-rpath=/home/hongze/anaconda3/envs/FSOD/lib,--no-as-needed -std=c99 ./_nms.o ./home/hongze/Documents/FSOD-code/lib/model/nms/src/nms_cuda.o /home/hongze/Documents/FSOD-code/lib/model/nms/src/nms_cuda_kernel.cu.o -L/home/hongze/anaconda3/envs/FSOD/lib -lpython3.6m -o ./_nms.so

☆另外,我解决了cuda.h找不到的问题后出现另一个问题:nms_cuda.c: No such file or directory

gcc: error: /home/hongze/Documents/FSOD-code/lib/model/nms/src/nms_cuda.c: No such file or directory

只需要在FSOD-code/lib/model/nms/src/自行加入该文件,点击查看nms_cuda.c文件内容:

This aims to fix issue #17. The compling error is actually caused by missing the file nms_cuda.c. I borrow the one in Detectron.pytorch.

  • 强制使用指定位置的nvcc:https://github.com/jwyang/faster-rcnn.pytorch/issues/55
  • 在make.sh文件前面添加这三行:
#export PATH=home/hongze/cudas/cuda-9.0/bin${PATH:+:${PATH}}
#export CPATH=home/hongze/cudas/cuda-9.0/include${CPATH:+:${CPATH}}
#export LD_LIBRARY_PATH=home/hongze/cudas/cuda-9.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
  • 自行创建软连接连接到cuda.h的:

For me, I don’t have root access. I can’t make such symlinks to the system. So I just symlinked to the problem dir and it works now. Not recommending this, just for those in a similar situation to me with whom no environmental variable setting has helped.

ln -s ~/cuda/include/* ~/anaconda3/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC/
  • 有人重新安装了pytorch0.4.0,然后解决了问题

Hi @huinsysu, do you solve the issue, I met the same error as yours. And I reinstall the pytorch0.4.0, then solve the issue.

  • 有人在make.h中指定了CUDA_ARCH的值:

Hope this is not too late. Actually all the solutions mentioned above does not work for me. I solved this by modifying the file ‘~/lib/make.sh’. In the file, please comment the CUDA_ARCH line and changed the ‘$CUDA_ARCH’ in each compilation into ‘-arch=arch’
Taking the nms package as an example, the previous command (line 20)is:
nvcc -c -o nms_cuda_kernel.cu.o nms_cuda_kernel.cu
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC $CUDA_ARCH
Now, we should change it as:
nvcc -c -o nms_cuda_kernel.cu.o nms_cuda_kernel.cu
-D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -arch=sm_52
Then conduct similar operations for other packages.
It should be noted that ‘arch’ is determined by your GPU type.-arch=sm_52’ works for TitanX. You could look at the Compilation Section in this Page or the documents of the NVCC for information of your GPU.
I am still a bit confused about the problem. I guess it results from the CUDA version.

  • 更多解决方法请查看:
    论文作者的指路,包含了4个Issue页面,点击查看:

You can reference here to find solutions: detectron-tw, stan-dev470, stan-dev622, stan-dev561

2.2 总结

知其然,却不知其所以然。

解决......lib/include/THC/THCGeneral.h:12:18: fatal error: cuda.h: No such file or directory报错问题相关推荐

  1. 成功解决Ubuntu下的include/darknet.h:14:14: fatal error: cuda_runtime.h: No such file or directory

    成功解决Ubuntu下的include/darknet.h:14:14: fatal error: cuda_runtime.h: No such file or directory 目录 解决问题 ...

  2. backports/lzma/_lzmamodule.c:115:18: fatal error: lzma.h: No such file or directory serWarning: Coul

    执行 /home/admin/env/acq-cluster-data-init/bin/pip install backports.lzma报错 服务器运行带有pandas的脚本报如下错误 /hom ...

  3. decode.c:38:18: fatal error: dnet.h: No such file or directory

    根据文档(Snort 2.9.7.x on Ubuntu 12 LTS and 14 LTS)为snort安装barnyard2的时候遇到问题: 缺少dnet.h头文件 decode.c:38:18: ...

  4. uwsgi 安装报错 plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory

    1. Python3 安装 uwsgi 报错 直接使用命令 sudo pip3 install uwsgi 安装如下错误: ubuntu@ubuntu:~/Downloads$ sudo pip3 i ...

  5. ubuntu + eigen3 安装(解决 fatal error: Eigen/Core: No such file or directory)

    ubuntu + eigen3 安装(解决 fatal error: Eigen/Core: No such file or directory) 转载链接:https://www.cnblogs.c ...

  6. Install matplotlib Error: src/ft2font.h:16:22: fatal error: ft2build.h: No such file or directory

    在ubuntu下从源码安装matplotlib的时候出现这样的错误: src/ft2font.h:16:22: fatal error: ft2build.h: No such file or dir ...

  7. /usr/include/c++/6/cstdlib:75:25: fatal error: stdlib.h: No such file or directory

    1.错误原因 报错如上.后来经过查阅,发现这个错误是因为由于gcc6的缘故.我的gcc 版本是6.5的.gcc6已经把吧stdlib.h纳入了libstdc++以进行更好的优化,C Library的头 ...

  8. 解决/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory报错

    /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory 今天在搭建一台新服务器的java环境,配置完环境变量后输入java ...

  9. 在Jetson Xavier NX上安装pycuda报错:src/cpp/cuda.hpp:14:10: fatal error: cuda.h: No such file or directory

    文章目录: 1 我的系统环境和遇到问题分析 1.1 我的系统环境 1.2 问题描述 2 问题解决方式 1 我的系统环境和遇到问题分析 1.1 我的系统环境 我的详细系统环境如下:使用jetson_re ...

  10. /usr/include/stdio.h:27:10: fatal error: bits/libc-header-start.h: No such file or directory 报错解决

    转自:https://blog.csdn.net/BakerTheGreat/article/details/104234472 在64位系统上编译32位可执行程序的命令如下所示: gcc -m32 ...

最新文章

  1. 一步一步教你在 Android 里创建自己的账号系统(一)
  2. 【整理】【转载】高薪是怎么跳出来的?
  3. c++ 自定义比较函数,运行时发生segmentation fault
  4. jQuery attr removeAttr 属性操作
  5. java网页解析包_java 网页解析工具包 Jsoup
  6. 【BZOJ4566】找相同字符,后缀数组
  7. IAR执行到断点处不能单步运行解决方法
  8. java s类型_javasript基础——数据类型与数据类型转换
  9. 页面加载速度优化的建议
  10. 文案“跑路”了,这是我们的新广告语
  11. photoshop 大作业
  12. 配置flashgot+axel
  13. 常用街机模拟器机台设置[更新中](新手看)
  14. 20.时空跳跃者的魔法
  15. android qq红点,手机QQ的拖动红点消除红点功能是怎么想出来的?
  16. 安装语音计算机到桌面,桌面百度推出 语音搜索技术让电脑听“人话”
  17. 【X3D: Expanding Architectures for Efficient Video Recognition】
  18. 阿里云服务器安装Docker
  19. 信息学奥赛一本通高手训练题解目录
  20. Linux Shell 使用手记

热门文章

  1. PPT中的图像如何导出不失真的矢量图
  2. java对excel插入水印_Java通过POI和JXL给Excel动态添加水印
  3. 卷积神经网络反向传播算法
  4. CrazyTalk Animator 3 for Mac破解版永久激活方法附破解补丁
  5. 你知道的用户研究方法有哪些? 你认为应该如何进行定性和定量的研究?
  6. Chrome 谷歌浏览器 google 复制网页上禁止复制的文本
  7. 什么是通配符 计算机网络,通配符
  8. 那些年我们一起追过的ILSVRC冠军
  9. 【PhotoShop】ps 基础知识
  10. libcef(一)编译CEF