OpenGL代码编译时出现undefined reference to `XineramaQueryExtension'是什么原因?如何解决?
问题描述:
我的c++程序使用了glfw和glad,编译环境中这两个都有,但编译时报如下错,如何解决?
报错信息:
//tmp/cco8XNYv.o: In function `main':
test2.cpp:(.text+0xdd): undefined reference to `gladLoadGLLoader'
/tmp/cco8XNYv.o: In function `framebuffer_size_callback(GLFWwindow*, int, int)':
test2.cpp:(.text+0x192): undefined reference to `glad_glViewport'
/usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x1b05): undefined reference to `XineramaQueryExtension'
x11_init.c:(.text+0x1b1d): undefined reference to `XineramaIsActive'
/usr/local/lib/libglfw3.a(x11_init.c.o): In function `_glfwCreateCursorX11':
x11_init.c:(.text+0x23ea): undefined reference to `XcursorImageCreate'
x11_init.c:(.text+0x2507): undefined reference to `XcursorImageLoadCursor'
x11_init.c:(.text+0x2515): undefined reference to `XcursorImageDestroy'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitors':
x11_monitor.c:(.text+0x682): undefined reference to `XineramaQueryScreens'
collect2: ld returned 1 exit status
编译命令:
g++ test.cpp -o test -lglfw3 -lGL -lX11 -lpthread -lXrandr -lXi
代码:
#include<glad/glad.h>
#include<GLFW/glfw3.h>
#include<iostream>
using namespace std;
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
int main()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(800, 600, "fly's window", NULL, NULL);
if(window == NULL)
{
cout << "Failed to create GLFW window" << endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
cout << "Failed to initialize GLAD" << endl;
return -1;
}
while(!glfwWindowShouldClose(window))
{
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
附:
操作系统是CentOS 6.10
glfw版本:3.2
glad版本:0.1.33
g++版本:4.4.7