-3

该代码是从 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

我可以为我的代码做什么?

4

1 回答 1

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.aorlibshrutil_x86_64.alibcutil.aorlibcutil_x86_64.a并且您想要通过使用开关指定这些库的路径并使用开关指定库名称(减去开头和结尾的 the)来将它们链接到-Llib.a程序-l.

于 2013-07-03T04:23:29.633 回答