Linux(X11)上GLFW上的链接器错误

Linker error on GLFW on linux (x11)

本文关键字:链接 错误 GLFW X11 Linux      更新时间:2023-10-16

我刚刚在ubuntu上安装了glfw3,我正在测试文档中的示例代码(http://www.glfw.org/documentation.html(,我遇到了这些错误。/p>

我尝试了添加-ldl之类的倍数,但似乎没有用。

这是错误日志(GCC(:

g++  -o bin/Debug/Game obj/Debug/main.o  -ldl -lglfw3 -lm -lGL -lGLU  
//usr/local/lib/libglfw3.a(vulkan.c.o): In function `_glfwInitVulkan':
vulkan.c:(.text+0x42): undefined reference to `dlopen'
vulkan.c:(.text+0xa9): undefined reference to `dlsym'
//usr/local/lib/libglfw3.a(vulkan.c.o): In function `_glfwTerminateVulkan':
vulkan.c:(.text+0x382): undefined reference to `dlclose'
//usr/local/lib/libglfw3.a(vulkan.c.o): In function `glfwGetInstanceProcAddress':
vulkan.c:(.text+0x72f): undefined reference to `dlsym'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `translateKeyCode':
x11_init.c:(.text+0x6a): undefined reference to `XkbKeycodeToKeysym'
x11_init.c:(.text+0x14a): undefined reference to `XkbKeycodeToKeysym'
x11_init.c:(.text+0x177): undefined reference to `XGetKeyboardMapping'
x11_init.c:(.text+0x191): undefined reference to `XFree'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `createKeyTables':
x11_init.c:(.text+0xc3e): undefined reference to `XkbGetMap'
x11_init.c:(.text+0xc61): undefined reference to `XkbGetNames'
x11_init.c:(.text+0x137f): undefined reference to `XkbFreeNames'
x11_init.c:(.text+0x1395): undefined reference to `XkbFreeKeyboard'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `hasUsableInputMethodStyle':
x11_init.c:(.text+0x14b2): undefined reference to `XGetIMValues'
x11_init.c:(.text+0x150c): undefined reference to `XFree'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `getSupportedAtom':
x11_init.c:(.text+0x155b): undefined reference to `XInternAtom'
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `detectEWMH':
x11_init.c:(.text+0x15ea): undefined reference to `XInternAtom'
x11_init.c:(.text+0x1610): undefined reference to `XInternAtom'
x11_init.c:(.text+0x1678): undefined reference to `XFree'
x11_init.c:(.text+0x16a1): undefined reference to `XFree'
x11_init.c:(.text+0x16ad): undefined reference to `XFree'
x11_init.c:(.text+0x16be): undefined reference to `XFree'
x11_init.c:(.text+0x16ca): undefined reference to `XFree'
//usr/local/lib/libglfw3.a(x11_init.c.o):x11_init.c:(.text+0x190d): more undefined references to `XFree' follow
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x194e): undefined reference to `dlopen'
x11_init.c:(.text+0x1993): undefined reference to `dlsym'
x11_init.c:(.text+0x19c1): undefined reference to `dlsym'
x11_init.c:(.text+0x19ef): undefined reference to `dlsym'
x11_init.c:(.text+0x1a1d): undefined reference to `dlsym'
x11_init.c:(.text+0x1a8b): undefined reference to `dlopen'
x11_init.c:(.text+0x1ad0): undefined reference to `dlsym'
x11_init.c:(.text+0x1afe): undefined reference to `dlsym'
x11_init.c:(.text+0x1b56): undefined reference to `XQueryExtension'
x11_init.c:(.text+0x1bdf): undefined reference to `dlopen'
x11_init.c:(.text+0x1c24): undefined reference to `dlsym'
x11_init.c:(.text+0x1c52): undefined reference to `dlsym'
x11_init.c:(.text+0x1c80): undefined reference to `dlsym'
x11_init.c:(.text+0x1cae): undefined reference to `dlsym'
x11_init.c:(.text+0x1cdc): undefined reference to `dlsym'
//usr/local/lib/libglfw3.a(x11_init.c.o):x11_init.c:(.text+0x1d0a): more undefined references to `dlsym' follow
//usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x214a): undefined reference to `dlopen'
x11_init.c:(.text+0x218f): undefined reference to `dlsym'
x11_init.c:(.text+0x21bd): undefined reference to `dlsym'
x11_init.c:(.text+0x21eb): undefined reference to `dlsym'
x11_init.c:(.text+0x220d): undefined reference to `dlopen'
x11_init.c:(.text+0x2252): undefined reference to `dlsym'
x11_init.c:(.text+0x2280): undefined reference to `dlsym'
x11_init.c:(.text+0x22ae): undefined reference to `dlsym'
x11_init.c:(.text+0x23b4): undefined reference to `XkbQueryExtension'
x11_init.c:(.text+0x23f3): undefined reference to `XkbSetDetectableAutoRepeat'
x11_init.c:(.text+0x2420): undefined reference to `dlopen'

链接物质时库的顺序。如果库A取决于库B,则在命令行上 B之前必须

在您的情况下,由于glfw3库取决于dl库,因此您必须切换订单,以便glfw3在命令行上的dl之前。

您还必须与X11库链接。

因此,完整的命令行应该看起来像

g++ -o bin/Debug/Game obj/Debug/main.o -lglfw3 -ldl -lm -lGL -lGLU -lX11