首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >链接错误LNK2005几个CUDA文件

链接错误LNK2005几个CUDA文件
EN

Stack Overflow用户
提问于 2012-04-04 12:50:12
回答 2查看 2K关注 0票数 1

我发现“链接错误LNK2005 .已经定义”的错误有一些问题。这些档案如下:

代码语言:javascript
复制
// 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)

那我就有了这个

代码语言:javascript
复制
// 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)

然后我有了内核标题:

代码语言:javascript
复制
#ifndef __BITMAPS_KERNEL__
#define __BITMAPS_KERNEL__

......  // 9 kernels definitions

#endif

最后,我有一个:

代码语言:javascript
复制
// 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

问题是,如果我不将#包含"Bitmaps_cuda.h"包含在Bitmap*.cu中,那么编译器当然会说我忽略了内核函数的定义。我读了很多帖子,我已经包括了“额外的待定”和所需的路径。当我添加Bitmap8.cu文件及其相关内核时,问题就开始了,因为在此之前,应用程序正常工作。

总之,这就是我所犯的错误:

代码语言:javascript
复制
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

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

提前谢谢你!

编辑

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

-一个绝对的定义是两次,每个定义都有不同的值。

事实上,正如我在底部所写的,我有这样的定义,但我不能改变。知道怎么解决吗?

再一次提前谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-04-09 06:49:47

这些错误是因为我双倍地包含了一个文件。问题解决了!

票数 2
EN

Stack Overflow用户

发布于 2012-04-04 15:57:06

然后我有内核标题:#ifndef __BITMAPS_KERNEL__ #define __BITMAPS_KERNEL__ .// 9内核定义#endif

您的意思是说您有9个内核声明,而不是定义?

不能将内核定义放在头文件中。

确保所有.cu文件都链接到同一个运行时(打开每个.cu文件上的属性表并比较CUDA C/C++ | Host | Runtime Library设置)。还要确保它与常规cpp文件使用的运行时相同。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10011460

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档