2

我尝试编译这个小 示例,但执行 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

我错过了什么?

4

3 回答 3

1

这些函数都是您平台的最小实现未提供的所有 OpenGL / GLX 扩展。

您必须在运行时使用 加载它们glXGetProcAddress (...),它们不包含在您直接链接到的任何库中。尽管您可以链接到诸如GLEW之类的扩展管理库来为您完成繁琐的工作,但您仍然需要做的不仅仅是添加新的链接依赖项。

您通常必须在创建 OpenGL 渲染上下文后初始化所述库。值得指出的是,将 WGL (Windows) 和 GLX (X11) 区分开来的一件事是,您不必在使用 GLX 加载扩展之前创建 GL 上下文,因此您可以实际加载,glXCreateContextAttribsARB在您拥有语境。但是,您获得的后两个函数指针是否会在运行时执行任何操作是另一回事,这取决于您创建的上下文的功能。glDispatchComputeglBindImageTexture

于 2014-01-24T18:52:37.350 回答
0

您忘记链接某些内容。如果您正在使用 GLEW,请确保您链接到 glew32.lib(或 libglew32.a 或任何适用于您的系统)。

于 2014-01-24T18:18:23.420 回答
0

未定义的引用意味着您没有链接到库

于 2014-01-24T18:12:45.930 回答