Question

I try to compile this small example and I have this error executing the make:

g++ -o ogl_cs_example main.cpp opengl_cs.cpp opengl_util.cpp -Wall -Iinclude -lX11 -lGL -lGLU
/tmp/ccFLIOt2.o: In function `updateTex(int)':
main.cpp:(.text+0xc6): undefined reference to `glDispatchCompute'
/tmp/ccQ8pShN.o: In function `genTexture()':
opengl_util.cpp:(.text+0x3df): undefined reference to `glBindImageTexture'
/tmp/ccQ8pShN.o: In function `initGL()':
opengl_util.cpp:(.text+0x7dd): undefined reference to `glXCreateContextAttribsARB'
collect2: error: ld returned 1 exit status
make: *** [example] Error 1

What am I missing?

Was it helpful?

Solution

Those functions are all OpenGL / GLX extensions that are not provided by your platform's minimal implementation.

You have to load them at run-time using glXGetProcAddress (...), they are not contained in any library that you link directly to. Though you can link to an extension managing library such as GLEW to do the dirty work for you, you will still have to do more than merely add a new linking dependency.

You generally have to initialize said libraries after you create your OpenGL render context. It is worth pointing out that one thing that sets WGL (Windows) and GLX (X11) apart is that you do not have to create a GL context before you can load extensions with GLX, so you can actually load glXCreateContextAttribsARB, glDispatchCompute and glBindImageTexture before you have a context. Whether the later two function pointers you get will do anything at run-time is a different story, however, and depends on the capabilities of the context you created.

OTHER TIPS

You are forgetting to link something. If you are using GLEW, make sure you are linking to glew32.lib (or libglew32.a or whatever for your system).

undefined reference means you did not LINK to the libraries

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top