Cuda错误:函数已在另一个.cu.obj文件中定义(Cuda error: function has already been defined in another .cu.obj file)

问 题

I am trying to compile a cuda project that someone sent me. Though the compile stage passes, the link stage is failing. Below is an example of the error:

Error   298 error LNK2005: "int __cdecl compare_ints(void const *,void const *)" (?compare_ints@@YAHPBX0@Z) already defined in 3level_1.cu.obj  decode_p4.cu.obj    

Basically, the file decode_p4.cu.obj is complaining that the function compare_ints is already defined in 3level_1.cu.obj. Any ideas on how to avoid this behaviour?

Below is a list of similar errors if that helps:

Error   384 error LNK2005: "int __cdecl compare_ints(void const *,void const *)" (?compare_ints@@YAHPBX0@Z) already defined in 3level_1.cu.obj  decode_p4.cu.obj    god
Error   385 error LNK2005: "int __cdecl cpu_intersection(unsigned int *,int,unsigned int *,int)" (?cpu_intersection@@YAHPAIH0H@Z) already defined in 3level_1.cu.obj    decode_p4.cu.obj    god
Error   386 error LNK2005: "int __cdecl intersection_cpu(unsigned int * * const,int * const,int)" (?intersection_cpu@@YAHQAPAIQAHH@Z) already defined in 3level_1.cu.obj    decode_p4.cu.obj    god
Error   387 error LNK2005: "void __cdecl sort_it(unsigned int * * const,int * const,int)" (?sort_it@@YAXQAPAIQAHH@Z) already defined in 3level_1.cu.obj decode_p4.cu.obj    god
Error   388 error LNK2005: "int __cdecl GPU_Intersection(unsigned int * * const,int * const,int,unsigned int *,unsigned int *,unsigned int *,struct uint4 *)" (?GPU_Intersection@@YAHQAPAIQAHHPAI22PAUuint4@@@Z) already defined in 3level_1.cu.obj decode_p4.cu.obj    god
Error   389 error LNK2005: "int __cdecl ceilPow2(int)" (?ceilPow2@@YAHH@Z) already defined in 3level_1.cu.obj   decode_p4.cu.obj    god
Error   390 error LNK2005: "void __cdecl recAllocate1(int,int)" (?recAllocate1@@YAXHH@Z) already defined in 3level_1.cu.obj decode_p4.cu.obj    god
Error   391 error LNK2005: "unsigned int __cdecl getceilPow2(unsigned int)" (?getceilPow2@@YAII@Z) already defined in 3level_1.cu.obj   decode_p4.cu.obj    god
Error   392 error LNK2005: "void __cdecl runTest(int,char * *)" (?runTest@@YAXHPAPAD@Z) already defined in 3level_1.cu.obj  decode_p4.cu.obj    god
Error   393 error LNK2005: "void __cdecl __device_stub__Z13scanBlockMAX1P5uint4S0_Pj(struct uint4 *,struct uint4 *,unsigned int *)" (?__device_stub__Z13scanBlockMAX1P5uint4S0_Pj@@YAXPAUuint4@@0PAI@Z) already defined in 3level_1.cu.obj  decode_p4.cu.obj    god
Error   394 error LNK2005: "void __cdecl scanBlockMAX1(struct uint4 *,struct uint4 *,unsigned int *)" (?scanBlockMAX1@@YAXPAUuint4@@0PAI@Z) already defined in 3level_1.cu.obj  decode_p4.cu.obj    god
Error   395 error LNK2005: "void __cdecl __device_stub__Z16scanBlockMAX1_gpP5uint4S0_Pj(struct uint4 *,struct uint4 *,unsigned int *)" (?__device_stub__Z16scanBlockMAX1_gpP5uint4S0_Pj@@YAXPAUuint4@@0PAI@Z) already defined in 3level_1.cu.obj    decode_p4.cu.obj    god

解决方案

This is just a guess, but if this is visual studio, I've seen this case before when the code is in a .cu file that is #included. In that case it should not also be compiled as a source file. To avoid this, right click on one of the files (hard to tell which from your description) and select properties, and then find and check the "exclude from build" check box.

本文地址:IT屋 » Cuda error: function has already been defined in another .cu.obj file

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值