help: linking error of cuPrintf demo

hello guys:

I write some codes with CUDA recently, and I want to track the variables on the GPU, so I download and attempt to use cuPrintf. but I received some linking error as following:

1>------ 已启动全部重新生成: 项目: Demo1, 配置: Debug Win32 ------

1>æ­£åœ¨åˆ é™¤é¡¹ç›®â€œDemo1”(配置“Debug|Win32”)çš„

中间文件和输出文件

1>Compiling…

1>cuPrintf.cu

1>e:/cuPrintf/Demo1/cuPrintf_Lib//cuPrintf.cu(309): warning: function “copyArg(char *, const char *, char *)” was declared but never referenced

1>tmpxft_00000d70_00000000-3_cuPrintf.cudafe1.gpu

1>tmpxft_00000d70_00000000-8_cuPrintf.cudafe2.gpu

1>e:/cuPrintf/Demo1/cuPrintf_Lib//cuPrintf.cu(309): warning: function “copyArg(char *, const char *, char *)” was declared but never referenced

1>tmpxft_00000d70_00000000-3_cuPrintf.cudafe1.cpp

1>tmpxft_00000d70_00000000-12_cuPrintf.ii

1>Compiling…

1>main.cu

1>tmpxft_00000e38_00000000-3_main.cudafe1.gpu

1>tmpxft_00000e38_00000000-8_main.cudafe2.gpu

1>tmpxft_00000e38_00000000-3_main.cudafe1.cpp

1>tmpxft_00000e38_00000000-12_main.ii

1>正在链接…

1>cuPrintf.obj : error LNK2005: _cudaPrintfInit 已经在 main.obj 中定义

1>cuPrintf.obj : error LNK2005: _cudaPrintfEnd 已经在 main.obj 中定义

1>cuPrintf.obj : error LNK2005: _cudaPrintfDisplay 已经在 main.obj 中定义

1>E:\cuPrintf\Debug\Demo1.exe : fatal error LNK1169: 找到一个或多个多重定义的符号

1>生成日志保存在“file://e:\cuPrintf\Demo1\Debug\BuildLog.htm”

1>Demo1 - 4 个error,2 个warning

========== 全部重新生成: 0 已成功, 1 已失败, 0 已跳过 ==========

The sample codes I used are from Jeremy Kemp(http://www.jeremykemp.co.uk/08/02/2010/cuda-cuprintf/),

#include <cuda.h>

#include “cuPrintf_Lib\cuPrintf.cu”

global void cuPrintfExample()

{

int tid;

tid = blockIdx.x * blockDim.x + threadIdx.x;

cuPrintf("%d\n", tid);

}

int main()

{

cudaPrintfInit();

cuPrintfExample <<< 5, 2 >>> ();

cudaPrintfDisplay(stdout, true);

cudaPrintfEnd();

return 0;

}

and I pasted them into a new source file named main.cu, so there are 3 files in my project, cuPrintf.cuh + cuPrintf.cu + main.cu, when I compiled it with VS2005 + CUDA2.3, such linking errors occurred.

would you please give me some advices ? thank you all !!

hello guys:

I write some codes with CUDA recently, and I want to track the variables on the GPU, so I download and attempt to use cuPrintf. but I received some linking error as following:

1>------ 已启动全部重新生成: 项目: Demo1, 配置: Debug Win32 ------

1>æ­£åœ¨åˆ é™¤é¡¹ç›®â€œDemo1”(配置“Debug|Win32”)çš„

中间文件和输出文件

1>Compiling…

1>cuPrintf.cu

1>e:/cuPrintf/Demo1/cuPrintf_Lib//cuPrintf.cu(309): warning: function “copyArg(char *, const char *, char *)” was declared but never referenced

1>tmpxft_00000d70_00000000-3_cuPrintf.cudafe1.gpu

1>tmpxft_00000d70_00000000-8_cuPrintf.cudafe2.gpu

1>e:/cuPrintf/Demo1/cuPrintf_Lib//cuPrintf.cu(309): warning: function “copyArg(char *, const char *, char *)” was declared but never referenced

1>tmpxft_00000d70_00000000-3_cuPrintf.cudafe1.cpp

1>tmpxft_00000d70_00000000-12_cuPrintf.ii

1>Compiling…

1>main.cu

1>tmpxft_00000e38_00000000-3_main.cudafe1.gpu

1>tmpxft_00000e38_00000000-8_main.cudafe2.gpu

1>tmpxft_00000e38_00000000-3_main.cudafe1.cpp

1>tmpxft_00000e38_00000000-12_main.ii

1>正在链接…

1>cuPrintf.obj : error LNK2005: _cudaPrintfInit 已经在 main.obj 中定义

1>cuPrintf.obj : error LNK2005: _cudaPrintfEnd 已经在 main.obj 中定义

1>cuPrintf.obj : error LNK2005: _cudaPrintfDisplay 已经在 main.obj 中定义

1>E:\cuPrintf\Debug\Demo1.exe : fatal error LNK1169: 找到一个或多个多重定义的符号

1>生成日志保存在“file://e:\cuPrintf\Demo1\Debug\BuildLog.htm”

1>Demo1 - 4 个error,2 个warning

========== 全部重新生成: 0 已成功, 1 已失败, 0 已跳过 ==========

The sample codes I used are from Jeremy Kemp(http://www.jeremykemp.co.uk/08/02/2010/cuda-cuprintf/),

#include <cuda.h>

#include “cuPrintf_Lib\cuPrintf.cu”

global void cuPrintfExample()

{

int tid;

tid = blockIdx.x * blockDim.x + threadIdx.x;

cuPrintf("%d\n", tid);

}

int main()

{

cudaPrintfInit();

cuPrintfExample <<< 5, 2 >>> ();

cudaPrintfDisplay(stdout, true);

cudaPrintfEnd();

return 0;

}

and I pasted them into a new source file named main.cu, so there are 3 files in my project, cuPrintf.cuh + cuPrintf.cu + main.cu, when I compiled it with VS2005 + CUDA2.3, such linking errors occurred.

would you please give me some advices ? thank you all !!

cudaPrintfInit(), cudaPrintfDisplay() and cudaPrintfEnd() are (or should be) in cuPrintf.cu cuPrintf.cu is included in your sourcefile. You shouldn’t therefore compile it separately (1>Compiling… 1>cuPrintf.cu). I can’t read the characters, maybe the linker complains the init etc. functions are doubly-defined?

cudaPrintfInit(), cudaPrintfDisplay() and cudaPrintfEnd() are (or should be) in cuPrintf.cu cuPrintf.cu is included in your sourcefile. You shouldn’t therefore compile it separately (1>Compiling… 1>cuPrintf.cu). I can’t read the characters, maybe the linker complains the init etc. functions are doubly-defined?

yes, your advice is good, I renamed cuPrintf.cu to cuPrintf1.cuh, and the project was linked correctly, Thank you very much. :)

yes, your advice is good, I renamed cuPrintf.cu to cuPrintf1.cuh, and the project was linked correctly, Thank you very much. :)