在Linux下编译最初在Windows下开发的CUDA代码时出错

时间:2013-06-30 17:19:15

标签: linux windows cuda

代码是从Windows系统开发的,当我在Linux系统中通过命令编译我的CUDA代码时:

nvcc lbm.cu -I/usr/local/cuda_sdk/CUDALibraries/common/inc -lm

编译器输出为:

In file included from lbm.cu:15:
lbm_kernel.h:52:8: warning: extra tokens at end of #endif directive
In file included from lbm.cu:15:
lbm_kernel.h:52:8: warning: extra tokens at end of #endif directive
/tmp/tmpxft_00001fda_00000000-13_lbm.o: In function "main":
tmpxft_00001fda_00000000-1_lbm.cudafe1.cpp:(.text+0xce7): undefined reference to "cutCheckCmdLineFlag"
tmpxft_00001fda_00000000-1_lbm.cudafe1.cpp:(.text+0x2103): undefined reference to "diff_wz_w(dim3, int, double*, double*, double*)"
tmpxft_00001fda_00000000-1_lbm.cudafe1.cpp:(.text+0x2143): undefined reference to "double gpu_sum<double>(int, int, int, int, int, double*, double*, double*)"
tmpxft_00001fda_00000000-1_lbm.cudafe1.cpp:(.text+0x21ca): undefined reference to "fabs_wz(dim3, int, double*, double*)"
tmpxft_00001fda_00000000-1_lbm.cudafe1.cpp:(.text+0x220a): undefined reference to "double gpu_sum<double>(int, int, int, int, int, double*, double*, double*)"
tmpxft_00001fda_00000000-1_lbm.cudafe1.cpp:(.text+0x22a3): undefined reference to "cpy(dim3, int, double*, double*)"
tmpxft_00001fda_00000000-1_lbm.cudafe1.cpp:(.text+0x2320): undefined reference to "lbm_step(dim3, int, int, double*)"
tmpxft_00001fda_00000000-1_lbm.cudafe1.cpp:(.text+0x23b5): undefined reference to "lbm_bounce_back_exit_inlet(dim3, int, int, float, float, double*, double*)"
tmpxft_00001fda_00000000-1_lbm.cudafe1.cpp:(.text+0x248f): undefined reference to "lbm_bounce_back_hole_wall_1(dim3, int, int, float, float, int, int, int, int, int, int, double*, double*)"
tmpxft_00001fda_00000000-1_lbm.cudafe1.cpp:(.text+0x2501): undefined reference to "lbm_bounce_back_wall_2(dim3, int, int, double*)"
tmpxft_00001fda_00000000-1_lbm.cudafe1.cpp:(.text+0x25a2): undefined reference to "lbm_stream(dim3, int, int, double*, double*)"
tmpxft_00001fda_00000000-1_lbm.cudafe1.cpp:(.text+0x2643): undefined reference to "lbm_den_vel(dim3, int, int, double*, double*, double*, double*, double*)"
/tmp/tmpxft_00001fda_00000000-13_lbm.o: In function "__cutilExit(int, char**)": 
tmpxft_00001fda_00000000-1_lbm.cudafe1.cpp:(.text._Z11__cutilExitiPPc[__cutilExit(int, char**)]+0x21): undefined reference to "cutCheckCmdLineFlag"
/tmp/tmpxft_00001fda_00000000-13_lbm.o: In function "cutilDeviceInit(int, char**)':    
tmpxft_00001fda_00000000-1_lbm.cudafe1.cpp:(.text._Z15cutilDeviceInitiPPc[cutilDeviceInit(int, char**)]+0x8b): undefined reference to "cutGetCmdLineArgumenti"
collect2: ld returned 1 exit status

我的代码可以做些什么?

1 个答案:

答案 0 :(得分:1)

您需要包含包含仍然列为“未定义引用:

”的函数的库
cutCheckCmdLineFlag
cutGetCmdLineArgument

使用编译命令行的修改可能会将这些函数添加到链接进程中,如下所示:

nvcc lbm.cu -I/usr/local/cuda_sdk/CUDALibraries/common/inc -L/usr/local/cuda_sdk/shared/lib -lshrutil -lcutil -lm

无论如何,您要查找库libshrutil.alibshrutil_x86_64.a以及libcutil.alibcutil_x86_64.a,并希望通过指定这些库的路径将它们链接到您的程序中使用-L开关并使用lib开关指定库名称(开头减去.a,最后减去-l)。