编译程序时未定义的引用`cudaFree'和许多其他错误

时间:2017-08-06 19:10:43

标签: makefile compiler-errors cuda

当我尝试编译我的CUDA程序时,出现以下错误:

b.o: In function `mul_wrapper':
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0xcb): undefined reference to `cudaConfigureCall'
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0xe7): undefined reference to `cudaDeviceSynchronize'
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x144): undefined reference to `cudaFree'
b.o: In function `cudaError cudaMallocManaged<float>(float**, unsigned long, unsigned int)':
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x18a): undefined reference to `cudaMallocManaged'
b.o: In function `__device_stub__Z3mulPf(float*)':
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x1df): undefined reference to `cudaSetupArgument'
b.o: In function `cudaError cudaLaunch<char>(char*)':
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x221): undefined reference to `cudaLaunch'
b.o: In function `__sti____cudaRegisterAll_36_tmpxft_00002a64_00000000_7_b_cpp1_ii__Z3mulPf()':
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x243): undefined reference to `__cudaRegisterFatBinary'
b.o: In function `__nv_cudaEntityRegisterCallback(void**)':
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x2f2): undefined reference to `__cudaRegisterFunction'
b.o: In function `__cudaUnregisterBinaryUtil()':
/tmp/tmpxft_00002a64_00000000-13_b.ii:(.text+0x31b): undefined reference to `__cudaUnregisterFatBinary'
collect2: error: ld returned 1 exit status
Makefile:3: recipe for target 'run' failed
make: *** [run] Error 1

我的make文件如下所示:

run: main.o b.o

    gcc -fPIC -L /usr/local/cuda/lib -lcudart -o run main.o b.o



main.o: main.c b.h

    gcc -fPIC -I /usr/local/cuda/include -c -o main.o main.c



b.o: b.cu b.h

    nvcc -Xcompiler -fPIC -ccbin clang-3.8 -c -o b.o b.cu

似乎问题与我的系统上找不到文件“/ usr / local / cuda / include”和“/ usr / local / cuda / lib”有关。我使用的是Ubuntu 17.04并且已经使用apt安装了CUDA工具包。我听说用apt安装CUDA工具包不会创建/ usr / local / cuda / *文件,所以我尝试从运行文件安装它,但是要安装faild。

更新:我重新安装了CUDA工具包,现在我有/ usr / local / cuda / *目录,但问题仍然存在。

0 个答案:

没有答案