Leon C. 2020-05-06 09:35 采纳率: 0%
浏览 1062
已采纳

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

  • 写回答

1条回答 默认 最新

  • zqbnqsdsmd 2020-05-06 11:07
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog