链接错误LNK2005几个CUDA文件 [英] Link error LNK2005 several CUDA files

查看:285
本文介绍了链接错误LNK2005几个CUDA文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一些错误链接错误LNK2005 ...已定义的问题。文件如下:

  //文件Bitmap4.cu 
#includeBitmap4.h// header
#includeBitmaps_cuda.h//只有内核定义的头

..... //我调用3 + 2内核函数(3在一个方法,1在另一个和另一个)

然后我有这个:

  // File Bitmap8.cu 
#includeBitmap8.h// header
#includeBitmaps_cuda.h//同上面的

..... //我调用4个内核函数(4在同一方法)

然后我有内核头:

  #ifndef __BITMAPS_KERNEL__ 
#define __BITMAPS_KERNEL__

...... // 9内核定义

#endif

最后,我有这个:

  // File Bitmaps_cuda.h 
#include< cuda.h>
#include< cuda_runtime.h>
#include< device_launch_parameters.h>
#include< device_functions.h>
#include< stdio.h>

//这里有所有内核函数,文件
// Bitmap4.cu和Bitmap8.cu使用

问题是,如果我不在位图* .cu中包含 #includeBitmaps_cuda.h当然,编译器会说我错过了内核函数的定义。我读了很多帖子,我已经包括了额外的Dipendencies和所需的PATH。当我添加文件Bitmap8.cu与它的相对内核,因为之前,应用程序正常工作开始的问题。



无论如何,这些是我有的错误:

  1> ; Bitmap8.cu.obj:错误LNK2005:void *的__cdecl big_random_block(INT(big_random_block @@ YAPAXH @ Z)在Bitmap4.cu.obj 
1 GT已经定义; Bitmap8.cu.obj:错误LNK2005: ?为int * __cdecl big_random_block_int(INT(big_random_block_int @@ YAPAHH @ Z)中已经定义Bitmap4.cu.obj
1 GT; Bitmap8.cu.obj:错误LNK2005:unsigned char型__cdecl值(浮球,浮球,INT(已经定义在Bitmap4.cu.obj
1> Bitmap8.cu.obj:error LNK2005:void * __cdecl start_thread(unsigned int(__ stdcall *)(void *),void * )(?start_thread @@ YAPAXP6GIPAX @ Z0 @ Z)已经在Bitmap4.cu.obj中定义
1> Bitmap8.cu.obj:error LNK2005:void __cdecl end_thread(void *)(?end_thread @@ YAXPAX @ Z)在Bitmap4.cu.obj
1 GT已经定义; Bitmap8.cu.obj:错误LNK2005:无效__cdecl destroy_thread(无效*)(destroy_thread @@ YAXPAX @ Z)已经Bitmap4定义。 cu.obj
1> Bitmap8.cu.obj:error LNK2005:void __cdecl wait_for_threads(void * const *,int)(?wait_for_threads @@ YAXPBQAXH @ Z)已经在Bitmap4.cu.obj
1 GT; Bitmap8.cu.obj:错误LNK2005:(?__ device_stub__Z14float_to_colorPhPKf @@ YAXPAEPBM @ Z)作废__cdecl__device_stub__Z14float_to_colorPhPKf(无符号字符*,浮动常量*),在Bitmap4.cu.obj
1 GT已经定义; Bitmap8 .cu.obj:错误LNK2005:无效__cdecl float_to_color(无符号字符*,* float_const)(?float_to_color @@ YAXPAEPBM @ Z)在Bitmap4.cu.obj
1 GT已经定义; Bitmap8.cu.obj:错误LNK2005:无效__cdecl__device_stub__Z14float_to_colorP6uchar4PKf(结构uchar4 *,浮动常量*),在Bitmap4.cu.obj
1 GT已经定义; Bitmap8.cu.obj(__ device_stub__Z14float_to_colorP6uchar4PKf @@ YAXPAUuchar4 @@ PBM @ Z):错误LNK2005 :void __cdecl float_to_color(struct uchar4 *,float_const *)(?float_to_color @@ YAXPAUuchar4 @@ PBM @ Z)已经在Bitmap4.cu.obj中定义

1> C:\Users\\ \\dberdin\documents\visual工作室2010\Projects\gpuSPAM\Debug\gpuSPAM.exe:致命错误LNK1169:一个或多个相乘定义的符号找到

我尝试了不同的解决方案,但是有任何结果。




$ b

EDIT



在网站( http://msdn.microsoft.com/en-us/library/72zdcz6f.aspx )我发现,那些原因之一错误是:

- 绝对定义两次,每个定义的值不同。

实际上,我有这些类型的定义,但我不能做不同。



解决方案

p>这些错误来了,因为我双包括一个文件。问题解决了!


I got some problems with the error "Link error LNK2005 ... already defined". The files are as follows:

// File Bitmap4.cu
#include "Bitmap4.h" // header
#include "Bitmaps_cuda.h" // header with just the definitions of the kernels

..... // I call 3+2 kernel functions (3 in one method, 1 in another and 1 in another one)

Then I have this one:

// File Bitmap8.cu
#include "Bitmap8.h" // header
#include "Bitmaps_cuda.h" // the same as above

..... // I call 4 kernel functions (4 in the same method)

Then I have the kernel header:

#ifndef __BITMAPS_KERNEL__
#define __BITMAPS_KERNEL__

......  // 9 kernels definitions

#endif

And finally, I have this one:

// File Bitmaps_cuda.h
#include <cuda.h>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
#include <device_functions.h>
#include <stdio.h>

// Inside here there all the kernel functions that the files 
// Bitmap4.cu and Bitmap8.cu are using

The problem is that, if i don't include the #include "Bitmaps_cuda.h" in one of the Bitmap*.cu, of course, the compiler will say that I missed the definitions of the kernels functions. I read a lot of posts and i already included the "Additional Dipendencies" and the required PATHs. The problems started when I added the file Bitmap8.cu with its relative kernels, because before that, the application was working properly.

Anyway, those are the error that i have:

1>Bitmap8.cu.obj : error LNK2005: "void * __cdecl big_random_block(int(?big_random_block@@YAPAXH@Z) already defined in Bitmap4.cu.obj
1>Bitmap8.cu.obj : error LNK2005: "int * __cdecl big_random_block_int(int(?big_random_block_int@@YAPAHH@Z) already defined in Bitmap4.cu.obj
1>Bitmap8.cu.obj : error LNK2005: "unsigned char __cdecl value(float,float,int(?value@@YAEMMH@Z) already defined in Bitmap4.cu.obj
1>Bitmap8.cu.obj : error LNK2005: "void * __cdecl start_thread(unsigned int(__stdcall*)(void *),void *)" (?start_thread@@YAPAXP6GIPAX@Z0@Z) already defined in Bitmap4.cu.obj
1>Bitmap8.cu.obj : error LNK2005: "void __cdecl end_thread(void *)"(?end_thread@@YAXPAX@Z) already defined in Bitmap4.cu.obj
1>Bitmap8.cu.obj : error LNK2005: "void __cdecl destroy_thread(void *)"(?destroy_thread@@YAXPAX@Z) already defined in Bitmap4.cu.obj
1>Bitmap8.cu.obj : error LNK2005: "void __cdecl wait_for_threads(void * const *,int)"(?wait_for_threads@@YAXPBQAXH@Z) already defined in Bitmap4.cu.obj
1>Bitmap8.cu.obj : error LNK2005: "void __cdecl__device_stub__Z14float_to_colorPhPKf(unsigned char *,float const *)"(?__device_stub__Z14float_to_colorPhPKf@@YAXPAEPBM@Z) already defined in Bitmap4.cu.obj
1>Bitmap8.cu.obj : error LNK2005: "void __cdecl float_to_color(unsigned char *,float_const *)" (?float_to_color@@YAXPAEPBM@Z) already defined in Bitmap4.cu.obj
1>Bitmap8.cu.obj : error LNK2005: "void __cdecl__device_stub__Z14float_to_colorP6uchar4PKf(struct uchar4 *,float const *)"(?__device_stub__Z14float_to_colorP6uchar4PKf@@YAXPAUuchar4@@PBM@Z) already defined in Bitmap4.cu.obj
1>Bitmap8.cu.obj : error LNK2005: "void __cdecl float_to_color(struct uchar4 *,float_const *)" (?float_to_color@@YAXPAUuchar4@@PBM@Z) already defined in Bitmap4.cu.obj

1>C:\Users\dberdin\documents\visual studio 2010\Projects\gpuSPAM\Debug\gpuSPAM.exe : fatal error LNK1169: one or more multiply defined symbols found

I tried different solutions but with any results.

Thank you in advance!

EDIT

On the website (http://msdn.microsoft.com/en-us/library/72zdcz6f.aspx) i found that one of the causes of those errors is:
- An absolute is defined twice, with a different value in each definition.
Well, actually, as i wrote in the bottom, i have these kind of definetions, but i can't do differently. Any idea how to solve it ?

Thank you again in advance

解决方案

Those errors came because i double included a file. Problem Solved!

这篇关于链接错误LNK2005几个CUDA文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆