2013-07-08 52 views
0

我是新来的Visual Studio,我想在我的CUDA代码中使用cuPrintf使用Visual Studio的CUDA代码2010LNK2005错误,同时为cuPrintf

#include "cuPrintf.cu" 
#include "cuPrintf.cuh" 

,但我收到以下错误

gpuLBMSolver.cu.obj : error LNK2005: "int __cdecl cuPrintf(char const *)" ([email protected]@[email protected]) already defined in cuPrintf.cu.obj 
1>gpuLBMSolver.cu.obj : error LNK2005: "void __cdecl cuPrintfRestrict(int,int)" ([email protected]@[email protected]) already defined in cuPrintf.cu.obj 
1>gpuLBMSolver.cu.obj : error LNK2005: _cudaPrintfInit already defined in cuPrintf.cu.obj 
1>gpuLBMSolver.cu.obj : error LNK2005: _cudaPrintfEnd already defined in cuPrintf.cu.obj 
1>gpuLBMSolver.cu.obj : error LNK2005: _cudaPrintfDisplay already defined in cuPrintf.cu.obj 

相同的代码我的Linux机器上工作正常... 在此先感谢

回答

0

你并不需要以包括.cu.cuh文件。你可以包含任何一个。

如果您包含.cu文件,请遵循.cuh文件中的注释中给出的示例,这就是您所需要做的。 如果包含.cuh文件,那么你也将需要建立.cu文件在您的项目,并在其链接

它也可能工作,如果你简单地恢复,包括文件的顺序:

#include "cuPrintf.cuh" 
#include "cuPrintf.cu" 

假设你没有尝试构建cuPrintf.cu在您的项目。

看起来您在代码中包含“cuPrintf.cu”,您在项目中分别构建cuPrintf.cu。你不能这样做。

由于您包含“cuPrintf.cu”,因此您需要从项目源文件中删除cuPrintf.cu文件。 (不要删除文件,只是删除它出现在你的项目源文件中的事实)。

+0

它不适用于我的代码...我仍然得到相同的错误... – amitdonanand

+0

更新了我的答案。你正在做一个'#include“cuPrintf.cu”'在你的文件中,*和*你分别在你的项目中建立'cuPrintf.cu'。不要在你的项目中建立'cuPrintf.cu'。只是包括它。 –

+0

谢谢,它的工作 – amitdonanand