c++ - Fail to build shared library using CMake and CUDA -
i'm trying build shared library containing cuda code using cmake. i'm using package findcuda. have problem in linking phase:
linking cxx shared library shlibcuda.so /usr/bin/c++ -fpic -std=c++0x -fopenmp -o3 -dndebug -shared -wl,-soname,shlibcuda.so -o shlibcuda.so cmakefiles/shlibcuda.dir/src/cuda/./shlibcuda_generated_calibrate.cu.o cmakefiles/shlibcuda.dir/src/cuda/./shlibcuda_generated_cleaning.cu.o cmakefiles/shlibcuda.dir/./shlibcuda_intermediate_link.o -l/usr/local/cuda-6.5/lib64/libcudart.so -wl,-rpath,/mylibs/lib:/usr/local/cuda-6.5/lib64 /usr/bin/ld: cmakefiles/shlibcuda.dir/./shlibcuda_intermediate_link.o: relocation r_x86_64_32s against `__nv_module_id' can not used when making shared object; recompile -fpic cmakefiles/shlibcuda.dir/./shlibscuda_intermediate_link.o: error adding symbols: bad value
from this question , answer found maybe problem 1 of object file linked not compiled -fpic
option. added -xcompiler -fpic
cuda_nvcc_flags.
in fact, can see in line below, when build process reaches building of called intermediate link file, no -fpic
passed compiler:
[100%] building nvcc intermediate link file cmakefiles/shlibcuda.dir/./shlibcuda_intermediate_link.o /usr/local/cuda-6.5/bin/nvcc -m64 -ccbin "/usr/bin/cc" -dlink cmakefiles/shlibcuda.dir/src/cuda/./shlibcuda_generated_calibrate.cu.o cmakefiles/shlibcuda.dir/src/cuda/./shlibcuda_generated_cleaning.cu.o -o cmakefiles/shlibcuda.dir/./shlibcuda_intermediate_link.o
my nvcc flags following:
#cuda include directories find_package(cuda required) set(cuda_nvcc_flags ${cuda_nvcc_flags}; -xcompiler -fpic; -o3; -gencode arch=compute_32,code=sm_32; -ccbin /usr/bin/g++ -std=c++11)
what doing wrong? if problem lack of -fpic
, how pass option when compiling intermediate link file?
i'm using cuda 6.5 , i'm passing -ccbin /usr/bin/g++ -std=c++11
option because need use c++11 in host code.
my cmake: 2.8.12.2.
it cmake problem resolved this patch (included since cmake 3.2.0). -fpic
flag passed when compiling intermediate link file.
however problem arised, since in configuration have pass explicitly host compiler:
[100%] building nvcc intermediate link file cmakefiles/shlibcuda.dir/./shlibcuda_intermediate_link.o /usr/local/cuda-6.5/bin/nvcc -xcompiler -fpic -o3 -gencode arch=compute_32,code=sm_32 -ccbin /usr/bin/g++ -std=c++11 -m64 -ccbin "/usr/bin/gcc-4.8" -dlink cmakefiles/shlibcuda.dir/src/cuda/./shlibcuda_generated_calibrate.cu.o cmakefiles/shlibcuda.dir/src/cuda/./shlibcuda_generated_cleaning.cu.o -o cmakefiles/shlibcuda.dir/./shlibcuda_intermediate_link.o nvcc fatal : redefinition of argument 'compiler-bindir'
because -ccbin /usr/bin/g++ -std=c++11
, -ccbin "/usr/bin/gcc-4.8"
both present.
this known cmake open issue n. 0013674. discussion still ongoing applying patch attached in thread (it removes check on "-ccbin" in cuda_nvcc_flags) problem solved.
Comments
Post a Comment