我是visual studio的新手,我正在尝试使用visual studio 2010在我的cuda代码中使用cuPrintf。
#include "cuPrintf.cu"
#include "cuPrintf.cuh"但是我得到了以下错误
gpuLBMSolver.cu.obj : error LNK2005: "int __cdecl cuPrintf(char const *)" (?cuPrintf@@YAHPBD@Z) already defined in cuPrintf.cu.obj
1>gpuLBMSolver.cu.obj : error LNK2005: "void __cdecl cuPrintfRestrict(int,int)" (?cuPrintfRestrict@@YAXHH@Z) 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机器上运行良好...提前感谢
发布于 2013-07-08 12:27:10
您不需要同时包含.cu和.cuh文件。您可以包括其中任何一个。
如果您按照.cuh文件中注释中给出的示例包含.cu文件,那么您需要做的就是这些。如果只包含.cuh文件,则还需要在项目中构建.cu文件,并将其链接到中。
如果您简单地颠倒包含文件的顺序,它也可能会起作用:
#include "cuPrintf.cuh"
#include "cuPrintf.cu"假设你不想在你的项目中构建cuPrintf.cu。
看起来您在代码中包含了" cuPrintf.cu“,并且在项目中单独构建了cuPrintf.cu。你不能这么做。
由于包含了" cuPrintf.cu ",因此需要从项目源文件中删除cuPrintf.cu文件。(不要删除该文件,只需删除它显示在要构建的项目源文件中的事实。)
https://stackoverflow.com/questions/17519094
复制相似问题