感谢:
https://blog.csdn.net/xiamentingtao/article/details/78266153
想要编译py-faster-rcnn然后测自己的数据集,但是在Cython时却报错了:
g++ -pthread -shared -B /home/ard/yes/compiler_compat -L/home/ard/yes/lib -Wl,-rpath=/home/ard/yes/lib,--no-as-needed build/temp.linux-x86_64-2.7/nms/nms_kernel.o build/temp.linux-x86_64-2.7/nms/gpu_nms.o -L/usr/local/cuda/lib64 -L/home/ard/yes/lib -R/usr/local/cuda/lib64 -lcudart -lpython2.7 -o /home/ard/py-faster-rcnn/lib/nms/gpu_nms.so
g++: error: unrecognized command line option ‘-R’
error: command 'g++' failed with exit status 1
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 1
解决办法:先将报错的nms.gpu_nms模块注释后重新make,打开setup.py,注释掉nms.gpu_nms模块:
# Extension('nms.gpu_nms',
# ['nms/nms_kernel.cu', 'nms/gpu_nms.pyx'],
# library_dirs=[CUDA['lib64']],
# libraries=['cudart'],
# language='c++',
# runtime_library_dirs=[CUDA['lib64']],
# # this syntax is specific to this build system
# # we're only going to use certain compiler args with nvcc and not with
# # gcc the implementation of this trick is in customize_compiler() below
# extra_compile_args={'gcc': ["-Wno-unused-function"],
# 'nvcc': ['-arch=sm_35',
# '--ptxas-options=-v',
# '-c',
# '--compiler-options',
# "'-fPIC'"]},
# include_dirs = [numpy_include, CUDA['include']]
# ),
也就是先编译utils/bbox.c和nms/cpu_nms.c及’pycocotools/_mask.c。然后再去掉上面的注释后,将报错的命令中含“-R"的一句替换为“-WI,rpath=”
-R/usr/local/cuda/lib64 -lcudart -lpython2.7 -o /home/ard/py-faster-rcnn/lib/nms/gpu_nms.so
换为:
-WI,rpath=/usr/local/cuda/lib64 -lcudart -lpython2.7 -o /home/ard/py-faster-rcnn/lib/nms/gpu_nms.so
然后再make一次便可以将gpu_nms模块编译好了,最终结果:
[caiyong.wang@localhost lib]$ make
python setup.py build_ext --inplace
running build_ext
skipping 'utils/bbox.c' Cython extension (up-to-date)
skipping 'nms/cpu_nms.c' Cython extension (up-to-date)
skipping 'nms/gpu_nms.cpp' Cython extension (up-to-date)
skipping 'pycocotools/_mask.c' Cython extension (up-to-date)
rm -rf build