While compiling this hello world sample in Ubuntu 10.10
This is from CUDA by Example, chapter 3 (No compile instructions provided >:@)
#include <iostream>
__global__ void kernel (void){
}
int main(void){
kernel <<<1,1>>>();
printf("Hellow World!\n");
return 0;
}
I got this:
$ nvcc -lcudart hello.cu hello.cu(11): error: identifier “printf” is
undefined1 error detected in the compilation of
“/tmp/tmpxft_00007812_00000000-4_hello.cpp1.ii”.
Why? How should this code be compiled?
You need to include
stdio.horcstdionotiostream(which is forstd::coutstuff) forprintf(seeman 3 printf). I found the source code for the book here.chapter03/hello_world.cuis actually:Where
../common/book.hincludesstdio.h.The
README.txtfile details how to compile the examples: