链接出问题

程序中出现这个问题:
error LNK2019: unresolved external symbol ___cudaRegisterLinkedBinary_49_tmpxft_000013c0_00000000_8_GPUCorrelation_cpp1_ii_94404af8 referenced in function “void __cdecl __sti____cudaRegisterAll_49_tmpxft_000013c0_00000000_8_GPUCorrelation_cpp1_ii_94404af8(void)” (?__sti____cudaRegisterAll_49_tmpxft_000013c0_00000000_8_GPUCorrelation_cpp1_ii_94404af8@@YAXXZ)
一直解决不了。。
这里有个类似的帖子:(不让发链接,我只好直接粘贴过来。。不好意思。。我只是想提供更多的信息而已)Hello,
I am working on Visual Studio 2008, using CUDA 5.0.
I am getting the following errors during linking:

Linking…
1>gqdtest_kernel.cu.obj : error LNK2019: unresolved external symbol ___cudaRegisterLinkedBinary_49_tmpxft_00001ed4_00000000_8_gqdtest_kernel_cpp1_ii_9571646c referenced in function “void __cdecl __sti____cudaRegisterAll_49_tmpxft_00001ed4_00000000_8_gqdtest_kernel_cpp1_ii_9571646c(void)” (?__sti____cudaRegisterAll_49_tmpxft_00001ed4_00000000_8_gqdtest_kernel_cpp1_ii_9571646c@@YAXXZ)
1>gqd_win.lib(common.cu.obj) : error LNK2019: unresolved external symbol ___cudaRegisterLinkedBinary_41_tmpxft_00001f38_00000000_8_common_cpp1_ii_4f760f83 referenced in function “void __cdecl __sti____cudaRegisterAll_41_tmpxft_00001f38_00000000_8_common_cpp1_ii_4f760f83(void)” (?__sti____cudaRegisterAll_41_tmpxft_00001f38_00000000_8_common_cpp1_ii_4f760f83@@YAXXZ)
1>gqd_win.lib(cuda_header.cu.obj) : error LNK2019: unresolved external symbol ___cudaRegisterLinkedBinary_46_tmpxft_00000e8c_00000000_8_cuda_header_cpp1_ii_e3ac5253 referenced in function “void __cdecl __sti____cudaRegisterAll_46_tmpxft_00000e8c_00000000_8_cuda_header_cpp1_ii_e3ac5253(void)” (?__sti____cudaRegisterAll_46_tmpxft_00000e8c_00000000_8_cuda_header_cpp1_ii_e3ac5253@@YAXXZ)

I have found ___cudaRegisterLinkedBinary in crt/host_runtime.h such as

crt/host_runtime.h:#define __REGISTERFUNCNAME_CORE(X) __cudaRegisterLinkedBinary##X
crt/host_runtime.h:#define ____cudaRegisterLinkedBinary(X) \

Could anyone help me to solve these errors?
Thank you
这个是第二个类似的帖子,其中说的第一个方法试了一下不得行,第二个方法不懂。。
I’m looking at simpleSeparateCompilation_vs2008.sln, which is part of the CUDA 5.0 samples package. The solution built successfully on the first try. I then made a slight modification (added whitespace) to simplieSeparateCompliation.cu and attempted to build the solution again. This resulted in a build error:

1>simpleSeparateCompilation.cu.obj : error LNK2019: unresolved external symbol ___cudaRegisterLinkedBinary_72_tmpxft_00001348_00000000_14_simpleSeparateCompilation_compute_35_cpp1_ii_e3db9f73 referenced in function “void __cdecl __sti____cudaRegisterAll_72_tmpxft_00001348_00000000_14_simpleSeparateCompilation_compute_35_cpp1_ii_e3db9f73(void)” (?__sti____cudaRegisterAll_72_tmpxft_00001348_00000000_14_simpleSeparateCompilation_compute_35_cpp1_ii_e3db9f73@@YAXXZ)

I’ve discovered two ways of getting around the error:

  1. Do a clean build / rebuild
  2. Delete simpleSeparateCompilation.device-link.obj prior to doing a build

Has anyone else encountered this problem? Any tips for avoiding the error?

Thanks.

万能的斑竹。。帮帮我吧。。谢谢

楼主您好,看上去像是您没有正确使用5.0的separation compilation导致的,
(但这个只是链接错误,而绝对不是“调试”问题)。

建议您检查如下2方面:
(1)您的项目里的所有.cu都使用了sm_20或者更高的编译选项。
(2)所有的.cu都要选择-rdc=true(即:generate relocatable device code)

或者您所有的.cu都不选择-rdc=true。

然后请重新rebuild all

期待您的反馈。

谢谢斑竹的解答。。检测了你说的两个方面,截图如下:[attach]3307[/attach]
还是出现错误,错误截图如下:
[attach]3308[/attach]
而且还有两点不明白:
第一:斑竹讲的separation compilation是什么啊?
第二:我只在一个.cu文件中选择了-rdc=true,sm-30,但是每个.cu都变成-rdc=true,sm-30了。。因此,斑竹说的这二点还不能理解,还望斑竹多多指点。。

亲,如果您不需要,请将所有的.cu(以及您的项目配置)中的rdc配置均改成No.

然后请重新rebuild all一次(在您的项目上点击右键,选择全部重建)。

如果您按照上述操作了,依然问题不变,那么可能需要其他会员、 版主、 NVIDIA原厂支持以及总版主为您回复了。

斑竹v587啊。。这样果然就行了。。但是这个是怎么回事呢?我这里是类似http://cudazone.nvidia.cn/forum/forum.php?mod=viewthread&tid=6344这个帖子的问题。。如果rdc改成No的话我就必须重新把一个函数写一遍。。能不能在保留rdc为true的前提下,消除这个错误了?谢谢

LZ您好:

使用CUDA 5.0的separation compilation或者不使用都是可以的,具体的方法见2#。

以及您不能因为您只试验成功了一种就质疑另外一种能否实现,这只是您某处还没有设置正确而已。

另外,在不使用5.0的separation compilation时,一般需要#include其他的.cu文件,并在解决方案中将已经#include的.cu文件排除生成。
若使用5.0的separation compilation,那么请不要#include其他的.cu文件,并在解决方案中将对应的.cu文件保留生成,他们将在分别编译之后,一同链接。

大致如此,您不妨检查一下。

祝您好运~

谢谢ice斑竹解答。还是有以下两个个问题
1:对separation compilation的定义不是很了解,在编程指南中找了一下也没有找到。不知道有没有相关资料;是不是让rdc=true就是separation compliation啊。。
2:“并在解决方案中将已经#include的.cu文件排除生成”这个怎么排除生成啊。。谢谢

LZ您好:

1:rdc=true就是使用 Relocatable Device Code也就是separate compilation。您可以在NVCC的手册中找到相关的信息。

2:在您解决方案的文件列表中,右键——属性——常规——从生成中排除。但是这个是不使用separate compilation时的做法,您使用separate compilation的话,无需这样。

大致如此,祝您调试顺利~

以及,补充下,如果使用-rdc=true的话,请注意:
(1)建议所有的.cu都要开启-rdc=true(或者直接对项目开启)。
(2)建议您的compute_*和sm_*配置必须完全符合你的卡。(您至少需要2.0计算能力的卡,否则不能用的)