c++ - GLEW 和 glfw 编译错误 : undefined reference to symbol 'XConvertSelection'

标签 c++ opengl glfw glew

我正在尝试编译这段代码:

#include <stdio.h>
#include <stdlib.h>

#include <GL/glew.h>

#include <GLFW/glfw3.h>
GLFWwindow* window;

#include <glm/glm.hpp>
using namespace glm;

int main( void )
{
    // Initialise GLFW
    if( !glfwInit() )
    {
        fprintf( stderr, "Failed to initialize GLFW\n" );
        return -1;
    }

    glfwWindowHint(GLFW_SAMPLES, 4);
    glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    // Open a window and create its OpenGL context
    window = glfwCreateWindow( 1024, 768, "Playground", NULL, NULL);
    if( window == NULL ){
        fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);

    // Initialize GLEW
    if (glewInit() != GLEW_OK) {
        fprintf(stderr, "Failed to initialize GLEW\n");
        return -1;
    }

    // Ensure we can capture the escape key being pressed below
    glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

    // Dark blue background
    glClearColor(0.0f, 0.0f, 0.4f, 0.0f);

    do{
        // Draw nothing, see you in tutorial 2 !

        // Swap buffers
        glfwSwapBuffers(window);
        glfwPollEvents();

    } // Check if the ESC key was pressed or the window was closed
    while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
           glfwWindowShouldClose(window) == 0 );

    // Close OpenGL window and terminate GLFW
    glfwTerminate();

    return 0;
}

这是我找到的有关 OpenGL 的教程中的代码,当涉及到 OpenGL 时,我主要使用 Java 进行编程,但我想尝试一些新的东西,所以我尝试使用 C++。

我正在为这个项目使用 QtCreator。 起初我包含了 GLEW 和 glfw3 库: enter image description here

glfw 库文件也是如此。

然后,当我尝试编译程序时出现此错误: enter image description here

在文本中:

$ /home/sapir/Qt/5.4/gcc_64/bin/qmake -spec linux-g++ CONFIG+=debug -o Makefile ../Test/Test.pro
$ g++ -Wl,-rpath,/home/sapir/Qt/5.4/gcc_64 -o Test main.o   -L/home/sapir/Dropbox/Development/Computer/openGLTest/Test/../../../../../../../usr/local/lib/ -lglfw3 -lGLEW -lGLEWmx 
/usr/bin/ld: /home/sapir/Dropbox/Development/Computer/openGLTest/Test/../../../../../../../usr/local/lib//libglfw3.a(glx_context.c.o): undefined reference to symbol 'glXQueryExtension'
//usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [Test] Error 1
23:12:13: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project Test (kit: Desktop Qt 5.4.0 GCC 64bit)
When executing step "Make"
23:12:13: Elapsed time: 00:00.

我厌倦了在论坛和这里寻找答案,但我找不到任何解决这个问题的方法。 有人有任何想法吗?

添加后

-lXxf86vm -lXrandr -lGL -lGLU -lXi

对于 gcc 编译器,我得到一个不同的错误,其中包含:

/usr/bin/ld: /home/sapir/Dropbox/Development/Computer/openGLTest/Test/../../../../../../../usr/local/lib//libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection'

这是我的生成文件:http://pastebin.com/xL5Hpwsf

这是我的 .pro 文件:http://pastebin.com/yhkV7nn7

最佳答案

好的,经过一些研究我发现我得到的 DSO 错误意味着我实现的包含的顺序不正确并导致编译失败。

所以我所做的是使用命令:

pkg-config --static --libs x11 xrandr xi xxf86vm glew glfw3

为了让它们以正确的顺序运行我需要的包。

然后我相应地编译了项目。 就是这样:)

关于c++ - GLEW 和 glfw 编译错误 : undefined reference to symbol 'XConvertSelection' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28531014/

相关文章:

javascript - 错误: cannot initialize return object of type 'Type *' with an rvalue of type 'bool'

opengl - OpenGL 中的投影矩阵真的是 "projection matrix"吗?

c - 包含 glad.h 时出现段错误

c++ - 关于c++继承的困惑

c++ - 用于大文件 I/O 的 mmap()?

c++ - 为什么这个 shared_ptr 代码会出现段错误? shared_ptr 什么时候免费?

opengl - opengl 函数会导致主线程卡住吗?

c++ - OpenGl表面和纹理

c++ - OpenGL 和 GLFW - 我需要着色器来绘制点吗?

c++ - 如何将正确的库与 GLFW 链接为 cmake 中的外部项目?