I got some problems with the error "Link error LNK2005 ... already defined". The files are as follows:
我在错误链接错误LNK2005中遇到了一些问题。已经定义”。文件如下:
// 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.
问题是,如果我不包含#include“Bitmaps_cuda”。在一个位图*中。当然,编译器会说我漏掉了内核函数的定义。我读了很多文章,我已经包括了“额外实习”和所需的路径。当我添加Bitmap8文件时,问题就开始了。cu及其相关内核,因为在此之前,应用程序运行正常。
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 ?
在网站(http://msdn.microsoft.com/en-us/library/72zdcz6f.aspx)上,我发现导致这些错误的原因之一是:-绝对定义了两次,每个定义的值都不一样。实际上,正如我在底部写的,我有这些定义,但我不能做不同的事情。你知道怎么解决吗?
Thank you again in advance
再次感谢您
2 个解决方案
#1
2
Those errors came because i double included a file. Problem Solved!
这些错误是因为我同时包含了一个文件。问题解决了!
#2
1
Then I have the kernel header: #ifndef __BITMAPS_KERNEL__ #define __BITMAPS_KERNEL__ ...... // 9 kernels definitions #endif
Did you mean to say that you have 9 kernel declarations, not definitions?
您是说您有9个内核声明,而不是定义吗?
You can't have the kernel definitions in a header file.
在头文件中不能有内核定义。
Make sure all your .cu files link to the same runtime (open the Properties sheet on each .cu file and comparing the CUDA C/C++ | Host | Runtime Library
settings.) Also make sure that is the same runtime as is used by your regular cpp files.
确保所有的.cu文件链接到相同的运行时(打开每个.cu文件的属性表,并比较CUDA C/ c++ |主机|运行时库设置)。还要确保与常规cpp文件使用的运行时相同。
#1
2
Those errors came because i double included a file. Problem Solved!
这些错误是因为我同时包含了一个文件。问题解决了!
#2
1
Then I have the kernel header: #ifndef __BITMAPS_KERNEL__ #define __BITMAPS_KERNEL__ ...... // 9 kernels definitions #endif
Did you mean to say that you have 9 kernel declarations, not definitions?
您是说您有9个内核声明,而不是定义吗?
You can't have the kernel definitions in a header file.
在头文件中不能有内核定义。
Make sure all your .cu files link to the same runtime (open the Properties sheet on each .cu file and comparing the CUDA C/C++ | Host | Runtime Library
settings.) Also make sure that is the same runtime as is used by your regular cpp files.
确保所有的.cu文件链接到相同的运行时(打开每个.cu文件的属性表,并比较CUDA C/ c++ |主机|运行时库设置)。还要确保与常规cpp文件使用的运行时相同。