Cuda9.0 compileing error when coming to g++ compiling step

Dear all,

My gcc and g++ version are both 4.8.5. My system is ubuntu18.04.
The two following steps have passed:

nvcc -D_DEBUG --use_fast_math -I"/usr/local/cuda-9.0//include" -I"/usr/include/eigen3" -I"/home/xingfu/NVIDIA_CUDA-9.0_Samples/common/inc" -dlink --machine 64 -arch=sm_50 -c -o kernel_cuda.o …/CudaTest/

g++ -c -pipe -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_CORE_LIB -I…/CudaTest -I. -I/usr/local/cuda-9.0/include -isystem /usr/include/eigen3 -I…/NVIDIA_CUDA-9.0_Samples/common/inc -isystem /usr/local/include -I…/Qt5.11.0/5.11.0/gcc_64/include -I…/Qt5.11.0/5.11.0/gcc_64/include/QtCore -I. -I…/Qt5.11.0/5.11.0/gcc_64/mkspecs/linux-g++ -o LBDM.o …/CudaTest/LBDM.cpp

However, when run the following step, the error occured:

g++ -Wl,-rpath,/home/xingfu/Qt5.11.0/5.11.0/gcc_64/lib -o CudaTest kernel_cuda.o LBDM.o -L/usr/local/cuda-9.0//lib64/ -lcuda -lcudart -lcublas -L/home/xingfu/CudaTest/…/…/…/usr/local/lib/ -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -L/home/xingfu/Qt5.11.0/5.11.0/gcc_64/lib -lQt5Core -lpthread

The compiler error shows:

kernel_cuda.o: In function __sti____cudaRegisterAll()’:
tmpxft_00000e7d_00000000-5_kernel.cudafe1.cpp:(.text+0x177e): undefined reference to__cudaRegisterLinkedBinary_41_tmpxft_00000e7d_00000000_6_kernel_cpp1_ii_channel’

How can I fix the error?


I add the -dlink, because it shows the error when dealing the following step:

nvcc -D_DEBUG --use_fast_math -I"/usr/local/cuda-9.0//include" -I"/usr/include/eigen3" -I"/home/xingfu/NVIDIA_CUDA-9.0_Samples/common/inc" --machine 64 -arch=sm_50 -c -o kernel_cuda.o …/CudaTest/

and the error is:

ptxas fatal : Unresolved extern function ‘cublasCreate_v2’

However, when I add -dlink, the error occured like I said above.

BTW, before I add -dlink, I can run a simple function in another test project like this:

global void add(float* x, float * y, float* z, int n)
int index = threadIdx.x + blockIdx.x * blockDim.x;
int stride = blockDim.x * gridDim.x;
for (int i = index; i < n; i += stride)
z[i] = x[i] + y[i];

After I add -dlink, the test project shows an error:

cuda_code_cuda.o: In function __sti____cudaRegisterAll()': tmpxft_000017db_00000000-5_cuda_code.cudafe1.cpp:(.text+0x861): undefined reference to __cudaRegisterLinkedBinary_44_tmpxft_000017db_00000000_6_cuda_code_cpp1_ii_5b538d80’

which is very similar to the above error.

Why does this happen? Why the g++ compiler can’t compile the object file after I add -dlink command to nvcc compiler?