Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 845
Programmer Avatar asked May 02 '26 08:05

Programmer


1 Answers

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.

like image 126
harrism Avatar answered May 05 '26 06:05

harrism



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!