problem compiling cuda_by_example

Hello,
I am trying to run the program julia_gpu.cu (chapter04). However, I am getting following error message

usr@usr-OEM:~/Desktop/usr/cuda_by_example/chapter04$ nvcc -lglut julia_gpu.cu
julia_gpu.cu(42): error: calling a host function(“cuComplex::cuComplex”) from a device/global function(“julia”) is not allowed

julia_gpu.cu(43): error: calling a host function(“cuComplex::cuComplex”) from a device/global function(“julia”) is not allowed

julia_gpu.cu(47): error: calling a host function(“cuComplex::cuComplex”) from a device/global function(“julia”) is not allowed

julia_gpu.cu(47): error: calling a host function(“cuComplex::cuComplex”) from a device/global function(“julia”) is not allowed

4 errors detected in the compilation of “/tmp/tmpxft_00002a4c_00000000-4_julia_gpu.cpp1.ii”.

I will be grateful if someone assists me in solving this issue. I am using Ubuntu 11.04 and have installed CUDA TOOLKIT 4.0.

– Akand

You just have to modify the constructor of the struct to:

__device__ cuComplex( float a, float b ) : r(a), i(b)  {}

Greetings

Cain

You just have to modify the constructor of the struct to:

__device__ cuComplex( float a, float b ) : r(a), i(b)  {}

Greetings

Cain

Thanks.

Thanks.

I had the same problem, but when I add “device” and compiling the code it turn out

giordi@giordi-PC:~/CUDA/Programmi$ nvcc 04-02-02-GPU.cu

/tmp/tmpxft_00000e7a_00000000-13_04-02-02-GPU.o: In function `CPUBitmap::display_and_exit(void (*)(void*))':

tmpxft_00000e7a_00000000-1_04-02-02-GPU.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x4e): undefined reference to `glutInit'

tmpxft_00000e7a_00000000-1_04-02-02-GPU.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x58): undefined reference to `glutInitDisplayMode'

tmpxft_00000e7a_00000000-1_04-02-02-GPU.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x6f): undefined reference to `glutInitWindowSize'

tmpxft_00000e7a_00000000-1_04-02-02-GPU.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x79): undefined reference to `glutCreateWindow'

tmpxft_00000e7a_00000000-1_04-02-02-GPU.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x83): undefined reference to `glutKeyboardFunc'

tmpxft_00000e7a_00000000-1_04-02-02-GPU.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x8d): undefined reference to `glutDisplayFunc'

tmpxft_00000e7a_00000000-1_04-02-02-GPU.cudafe1.cpp:(.text._ZN9CPUBitmap16display_and_exitEPFvPvE[CPUBitmap::display_and_exit(void (*)(void*))]+0x92): undefined reference to `glutMainLoop'

/tmp/tmpxft_00000e7a_00000000-13_04-02-02-GPU.o: In function `CPUBitmap::Draw()':

tmpxft_00000e7a_00000000-1_04-02-02-GPU.cudafe1.cpp:(.text._ZN9CPUBitmap4DrawEv[CPUBitmap::Draw()]+0x26): undefined reference to `glClearColor'

tmpxft_00000e7a_00000000-1_04-02-02-GPU.cudafe1.cpp:(.text._ZN9CPUBitmap4DrawEv[CPUBitmap::Draw()]+0x30): undefined reference to `glClear'

tmpxft_00000e7a_00000000-1_04-02-02-GPU.cudafe1.cpp:(.text._ZN9CPUBitmap4DrawEv[CPUBitmap::Draw()]+0x59): undefined reference to `glDrawPixels'

tmpxft_00000e7a_00000000-1_04-02-02-GPU.cudafe1.cpp:(.text._ZN9CPUBitmap4DrawEv[CPUBitmap::Draw()]+0x5e): undefined reference to `glFlush'

collect2: ld returned 1 exit status

I’m working on Ubuntu 11.04 and CUDA 4.1

G.

I have the same problem External Image HELP!

Hi I’ve solved it! Let’s hope this one is the solution: in the terminal write nvcc -lglut name.cu

Doesn’t work ;/

have you the lglut libraries? i’ve found the solution here on this forum, but i can’t remember where :(

G.

Hi,

I am trying to run the julia_gpu.cu on my mac. After having the following changes in the code I can compile it by

nvcc julia_gpu.cu -Xlinker -framework,OpenGL,-framework,GLUT -o julia_gpu.exe

first change is in gl_helper.h

/* On Linux, include the system’s copy of glut.h, glext.h, and glx.h */
#include

second one is in the julia_gpu.cu

// cuComplex( float a, float b ) : r(a), i(b) {}
device cuComplex( float a, float b ) : r(a), i(b) {}

However, when the exe file is called I get only a frozen screen which is the same with the one given in the book. Animation does not work. Why can it be so ?