I am new to visual studio and I am trying to use cuPrintf in my cuda code using visual studio 2010
#include "cuPrintf.cu"
#include "cuPrintf.cuh"
but I am getting the following error
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
The same code was working fine on my Linux machine... Thanks in advance
You don't need to include both the .cu
and the .cuh
file. You can include either one.
If you include the .cu
file, following the example given in the comments in the .cuh
file, that's all you need to do. If you include only the .cuh
file, then you will also need to build the .cu
file in your project, and link it in.
It might also work if you simply reverse the order of including the files:
#include "cuPrintf.cuh"
#include "cuPrintf.cu"
assuming you don't try to also build cuPrintf.cu
in your project.
It appears that you are including "cuPrintf.cu" in your code and you are separately building cuPrintf.cu in your project. You cannot do that.
Since you are including "cuPrintf.cu", you need to delete the cuPrintf.cu file from your project source files. (Don't delete the file, just delete the fact that it shows up in your project source files to be built.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.