openGL 3问题:对_glapi_tls_Dispatch的未定义引用

时间:2014-03-11 08:26:57

标签: c++ linux opengl compilation makefile

我正在尝试从http://open.gl/introduction编译一个简单的测试程序:

#include <GLFW/glfw3.h>
#include <thread>

int main()
{
    glfwInit();
    std::this_thread::sleep_for(std::chrono::seconds(1));
    glfwTerminate();
}

我使用以下代码编译:

>> g++ -c tutorial01.cpp -o tutorial01.o -std=c++11
>> g++  tutorial01.o -o tutorial01 -lglfw3 -lGL -lXrandr -lX11 -lXi -lGLEW
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libGL.so: undefined reference to `_glapi_tls_Dispatch'
collect2: error: ld returned 1 exit status

以下是有关此问题的一些额外信息:

>> readlink -f "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libGL.so"
/usr/lib/x86_64-linux-gnu/libGL.so.1.2.0

>> nm -D /usr/lib/x86_64-linux-gnu/libGL.so.1.2.0 | grep _glapi_tls_Dispatch
U _glapi_tls_Dispatch

>> ldd /usr/lib/x86_64-linux-gnu/libGL.so.1.2.0
linux-vdso.so.1 (0x00007fff0b200000)
libglapi.so.0 => /usr/lib/x86_64-linux-gnu/libglapi.so.0 (0x00007ff437f80000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007ff437d68000)
libXdamage.so.1 => /usr/lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007ff437b60000)
libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007ff437958000)
libX11-xcb.so.1 => /usr/lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007ff437750000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007ff437410000)
libxcb-glx.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-glx.so.0 (0x00007ff4371f8000)
libxcb-dri2.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-dri2.so.0 (0x00007ff436ff0000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007ff436dd0000)
libXxf86vm.so.1 => /usr/lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007ff436bc8000)
libdrm.so.2 => /usr/lib/x86_64-linux-gnu/libdrm.so.2 (0x00007ff4369b8000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff4366b0000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff436490000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff436288000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff435ed8000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007ff435cd0000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007ff435ac8000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff438428000)

>> nm -D /usr/lib/x86_64-linux-gnu/libglapi.so.0 |grep _glapi_tls_Dispatch
0000000000000000 D _glapi_tls_Dispatch

符号_glapi_tls_Dispatch在libglapi.so中定义,ligGL.so依赖于libglapi.so,为什么链接失败?

有没有人有线索?

1 个答案:

答案 0 :(得分:0)

快速搜索了libglfw3-dev软件包,它在我的系统上将库文件列为-lglfw而不是-lglfw3。 Dunno,如果这有帮助或没有。

apt-file search libglfw | grep -v doc
libglfw-dev: /usr/lib/x86_64-linux-gnu/libglfw.a
libglfw-dev: /usr/lib/x86_64-linux-gnu/libglfw.so
libglfw-dev: /usr/lib/x86_64-linux-gnu/pkgconfig/libglfw.pc
libglfw2: /usr/lib/x86_64-linux-gnu/libglfw.so.2
libglfw3: /usr/lib/x86_64-linux-gnu/libglfw.so.3
libglfw3: /usr/lib/x86_64-linux-gnu/libglfw.so.3.1
libglfw3-dev: /usr/lib/x86_64-linux-gnu/libglfw.so