CUDA BY EXAMPLE examples don't work

Hi,

I’m trying to compile the CUDA BY EXAMPLE examples but cannot make it run :S here’s the output of the compiler

BRabbit$ nvcc julia_gpu.cu In file included from ../common/cpu_bitmap.h:20,

                 from julia_gpu.cu:18:

../common/gl_helper.h:44:21: error: GL/glut.h: No such file or directory

../common/gl_helper.h:45:22: error: GL/glext.h: No such file or directory

../common/gl_helper.h:46:20: error: GL/glx.h: No such file or directory

Any ideas?

OS X has the OpenGL headers in a different place to the standard layout that code is written to expect. Rather than just GL/, headers are located in OpenGL/ and GLUT/. You will need to modify the preprocessor #include statements accordingly.

Hi thanks,

I change the #include statements but still the last one can’t be found

#include <GLUT/glut.h>

#include <OpenGL/glext.h>

#include <GL/glx.h>           //Didn't work

#include <GLUT/glx.h>      //the same

#include <OpenGL/glx.h>  // the same

is it that the last library doesn’t exist in Mac OS X?

the errors are the following:

Undefined symbols:

  "_glDrawPixels", referenced from:

      CPUBitmap::Draw()     in tmpxft_0000065a_00000000-12_julia_gpu.o

  "_glClear", referenced from:

      CPUBitmap::Draw()     in tmpxft_0000065a_00000000-12_julia_gpu.o

  "_glutInit", referenced from:

      CPUBitmap::display_and_exit(void (*)(void*))in tmpxft_0000065a_00000000-12_julia_gpu.o

  "_glFlush", referenced from:

      CPUBitmap::Draw()     in tmpxft_0000065a_00000000-12_julia_gpu.o

  "_glutMainLoop", referenced from:

      CPUBitmap::display_and_exit(void (*)(void*))in tmpxft_0000065a_00000000-12_julia_gpu.o

  "_glutInitDisplayMode", referenced from:

      CPUBitmap::display_and_exit(void (*)(void*))in tmpxft_0000065a_00000000-12_julia_gpu.o

  "_glutInitWindowSize", referenced from:

      CPUBitmap::display_and_exit(void (*)(void*))in tmpxft_0000065a_00000000-12_julia_gpu.o

  "_glutCreateWindow", referenced from:

      CPUBitmap::display_and_exit(void (*)(void*))in tmpxft_0000065a_00000000-12_julia_gpu.o

  "_glutDisplayFunc", referenced from:

      CPUBitmap::display_and_exit(void (*)(void*))in tmpxft_0000065a_00000000-12_julia_gpu.o

  "_glClearColor", referenced from:

      CPUBitmap::Draw()     in tmpxft_0000065a_00000000-12_julia_gpu.o

  "_glutKeyboardFunc", referenced from:

      CPUBitmap::display_and_exit(void (*)(void*))in tmpxft_0000065a_00000000-12_julia_gpu.o

ld: symbol(s) not found

collect2: ld returned 1 exit status

You need to link GLUT and OpenGL

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

Thanks a lot. I’m trying to learn also OpenGL.
Why do we have to link GLUT and OpenGL at compile time in Mac OS X? is it the same in all other OS?

Yes.

Hi,

I tried the same:

#include <GLUT/glut.h>

#include <OpenGL/glext.h>

#include <GLUT/glx.h> //the same

#include <OpenGL/glx.h> // the same

but I still have a little problem:

%nvcc julia_gpu.cu -Xlinker -framework,GLUT -Xlinker -framework,OpenGL

In file included from …/common/cpu_bitmap.h:20,

             from julia_gpu.cu:18:

…/common/gl_helper.h:47:38: error: GLUT/glx.h: No such file or directory

…/common/gl_helper.h:48:37: error: OpenGL/glx.h: No such file or directory

Thank you very much in advance for your help.

Change the following lines in your gl_helper.

from:
#else

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

To:

#else

/* On Linux, include the system’s copy of glut.h, glext.h, and glx.h */
#if defined(APPLE) || defined(MACOSX)
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#include <GL/glext.h>
#include <GL/glx.h>
#endif

It should work ( it works for me)

That’s great, Thank you so much! It works for me too! Perfect!

Actually in Mac OS X there’s no “glx.h” so just don’t use it mines work fine I use the following libraries:

#include <GLUT/glut.h>

#include <OpenGL/glext.h>

#include <OpenGL/glu.h>

#include <OpenGL/gl.h>

Hello, sorry for bringing this back from so long ago but I have a mac too and I’m trying to make the changes so I can run the code as well and I’m not doing something right.

So I essentially followed mfatica’s directions and changed the specified lines in my glhelper but still it doesn’t compile. Do I also need to do something else?

I still get the error

“In file included from …/common/cpu_bitmap.h:20,
from julia_gpu.cu:18:
…/common/gl_helper.h:51:21: error: GL/glut.h: No such file or directory
…/common/gl_helper.h:52:22: error: GL/glext.h: No such file or directory
…/common/gl_helper.h:53:21: error: GL/glx.h: No such file or directory”

Any help? Thanks

Try this tar file, everything should work aside from GL Interoperability.
Untar the file and type make in the main directory.

Edit: the system rejected .tgz files, now posted as .tar
cuda_by_example_mac.tar (670 KB)

Thanks mfatica for responding, but which tar file? I don’t see one attached.

edit: just made my email public if it’s easier to email it to me. Thanks again.

I also get this error:
In file included from julia_gpu.cu:18:
In file included from ./…/common/cpu_bitmap.h:20:
./…/common/gl_helper.h:17:2: error: unterminated conditional directive
#ifndef GL_HELPER_H

fixed adding and ENDIF at the bottom of gl_helper.h.
However, after this you need to modify a line in julia_gpu.cu:
change
cuComplex( float a, float b ) : r(a), i(b) {}
to
device cuComplex( float a, float b ) : r(a), i(b) {}
(see http://study.marearts.com/2015/03/error-calling-host-functioncucomplexcuc.html)

Finally, compile like:

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

and run a.out.