How to compile codes on CUDA OpenGL interop from the book CUDA BY EXAMPLE by Jason Sanders & Edw

I need some help in compiling the examples in the book which involve CUDA - OpenGL interoperability { heat.cu in chapter 8 }. i have tried to compile the code using

nvcc heat.cu -o heat

but i am getting a ton of errors thrown at me. I think i am missing out some compiler options which should take care of the openGL part. Can someone tell how to compile it from terminal in ubuntu ?

Error from compiling:

/Desktop/Cuda_Codes/Cuda_by_example/chapter08$ nvcc heat.cu -o heat
../common/gpu_anim.h(61): warning: conversion from a string literal to "char *" is deprecated
../common/gpu_anim.h(61): warning: conversion from a string literal to "char *" is deprecated
/tmp/tmpxft_00002690_00000000-16_heat.o: In function `GPUAnimBitmap::GPUAnimBitmap(int, int, void*)':
tmpxft_00002690_00000000-3_heat.cudafe1.cpp:(.text._ZN13GPUAnimBitmapC2EiiPv[_ZN13GPUAnimBitmapC5EiiPv]+0x103): undefined reference to `glutInit'
tmpxft_00002690_00000000-3_heat.cudafe1.cpp:(.text._ZN13GPUAnimBitmapC2EiiPv[_ZN13GPUAnimBitmapC5EiiPv]+0x10d): undefined reference to `glutInitDisplayMode'
tmpxft_00002690_00000000-3_heat.cudafe1.cpp:(.text._ZN13GPUAnimBitmapC2EiiPv[_ZN13GPUAnimBitmapC5EiiPv]+0x12a): undefined reference to `glutInitWindowSize'
tmpxft_00002690_00000000-3_heat.cudafe1.cpp:(.text._ZN13GPUAnimBitmapC2EiiPv[_ZN13GPUAnimBitmapC5EiiPv]+0x134): undefined reference to `glutCreateWindow'
tmpxft_00002690_00000000-3_heat.cudafe1.cpp:(.text._ZN13GPUAnimBitmapC2EiiPv[_ZN13GPUAnimBitmapC5EiiPv]+0x13e): undefined reference to `glXGetProcAddress'
/tmp/tmpxft_00002690_00000000-16_heat.o: In function `GPUAnimBitmap::anim_and_exit(void (*)(uchar4*, void*, int), void (*)(void*))':
E[_ZN13GPUAnimBitmap13anim_and_exitEPFvP6uchar4PviEPFvS2_E]+0x67): undefined reference to `glutMouseFunc'
tmpxft_00002690_00000000-3_heat.cudafe1.cpp:(.text._ZN13GPUAnimBitmap13anim_and_exitEPFvP6uchar4PviEPFvS2_E[_ZN13GPUAnimBitmap13anim_and_exitEPFvP6uchar4PviEPFvS2_E]+0x71): undefined reference to `glutIdleFunc'
tmpxft_00002690_00000000-3_heat.cudafe1.cpp:(.text._ZN13GPUAnimBitmap13anim_and_exitEPFvP6uchar4PviEPFvS2_E[_ZN13GPUAnimBitmap13anim_and_exitEPFvP6uchar4PviEPFvS2_E]+0x76): undefined reference to `glutMainLoop'
/tmp/tmpxft_00002690_00000000-16_heat.o: In function `GPUAnimBitmap::idle_func()':
tmpxft_00002690_00000000-3_heat.cudafe1.cpp:(.text._ZN13GPUAnimBitmap9idle_funcEv[_ZN13GPUAnimBitmap9idle_funcEv]+0xbe): undefined reference to `glutPostRedisplay'
/tmp/tmpxft_00002690_00000000-16_heat.o: In function `GPUAnimBitmap::Draw()':
tmpxft_00002690_00000000-3_heat.cudafe1.cpp:(.text._ZN13GPUAnimBitmap4DrawEv[_ZN13GPUAnimBitmap4DrawEv]+0x26): undefined reference to `glClearColor'
tmpxft_00002690_00000000-3_heat.cudafe1.cpp:(.text._ZN13GPUAnimBitmap4DrawEv[_ZN13GPUAnimBitmap4DrawEv]+0x30): undefined reference to `glClear'
tmpxft_00002690_00000000-3_heat.cudafe1.cpp:(.text._ZN13GPUAnimBitmap4DrawEv[_ZN13GPUAnimBitmap4DrawEv]+0x55): undefined reference to `glDrawPixels'
tmpxft_00002690_00000000-3_heat.cudafe1.cpp:(.text._ZN13GPUAnimBitmap4DrawEv[_ZN13GPUAnimBitmap4DrawEv]+0x5a): undefined reference to `glutSwapBuffers'
collect2: error: ld returned 1 exit status

download the cuda_by_example.zip file from here:

[url]http://developer.download.nvidia.com/books/cuda-by-example/cuda_by_example.zip[/url]

unzip it.

read the README.txt file.

It contains instructions for building the various codes.

Thank you for the help. I compiled as instructed in the README.txt file but I am getting the error below. I have tried to compile ripple.cu and there also i get the same error. Is there something wrong with my libraries ?

nvcc -lglut heat.cu -o heat
../common/gpu_anim.h(61): warning: conversion from a string literal to "char *" is deprecated

../common/gpu_anim.h(61): warning: conversion from a string literal to "char *" is deprecated

/usr/bin/ld: /tmp/tmpxft_00003460_00000000-16_heat.o: undefined reference to symbol 'glDrawPixels'
//usr/lib/nvidia-340/libGL.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

Normally, libraries need to be specified at the end of the command line. Have you tried:

nvcc heat.cu -o heat -lglut

Are you sure that GLUT is the only library that needs to be linked? FWIW, you can ignore the warnings. They are due to the fact that newer compilers treat string literals as ‘const char *’.

googling for that error message:

“libGL.so.1: error adding symbols: DSO missing from command line”

produced this hit which I think will be instructive:

[url]c++ - OpenGL library not linking - Stack Overflow

Try adding:

-lGL -lGLU

to the compile command.

Thank you both.

nvcc heat.cu -o heat -lglut -lGL -lGLU

this compiled correctly. I have checked the same with the ripple code and it works there as well.

Hi there. I am trying to compile heat.cu on a mac using:

nvcc -o heat heat.cu -Xlinker -framework,GLUT -Xlinker -framework,OpenGL

However, I got the following errors:

./../common/gpu_anim.h(27): error: identifier "PFNGLBINDBUFFERARBPROC" is undefined

./../common/gpu_anim.h(27): error: declaration is incompatible with "void glBindBuffer(GLenum, GLuint)"
/System/Library/Frameworks/OpenGL.framework/Headers/gl.h(2864): here

./../common/gpu_anim.h(28): error: identifier "PFNGLDELETEBUFFERSARBPROC" is undefined

./../common/gpu_anim.h(28): error: declaration is incompatible with "void glDeleteBuffers(GLsizei, const GLuint *)"
/System/Library/Frameworks/OpenGL.framework/Headers/gl.h(2865): here

./../common/gpu_anim.h(29): error: identifier "PFNGLGENBUFFERSARBPROC" is undefined

./../common/gpu_anim.h(29): error: declaration is incompatible with "void glGenBuffers(GLsizei, GLuint *)"
/System/Library/Frameworks/OpenGL.framework/Headers/gl.h(2866): here

./../common/gpu_anim.h(30): error: identifier "PFNGLBUFFERDATAARBPROC" is undefined

./../common/gpu_anim.h(30): error: declaration is incompatible with "void glBufferData(GLenum, GLsizeiptr, const GLvoid *, GLenum)"
/System/Library/Frameworks/OpenGL.framework/Headers/gl.h(2868): here


./../common/gpu_anim.h(67): error: identifier "PFNGLBINDBUFFERARBPROC" is undefined

./../common/gpu_anim.h(67): error: expected a ";"



16 errors detected in the compilation of "/var/folders/xb/y9hknkh97vd1cnbt20f_kbpm0000gn/T//tmpxft_00000364_00000000-9_heat.cpp1.ii".

any ideas in how to fix it? I was able to run previous chapters source files, but chapter 8.