GLEW和glfw编译错误:未定义引用符号'XConvertSelection' [英] GLEW and glfw compile error: undefined reference to symbol 'XConvertSelection'
问题描述
我正在尝试编译此代码:
#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)
{
//初始化GLFW
if(!glfwInit())
{
fprintf 无法初始化GLFW \\\
);
return -1;
}
glfwWindowHint(GLFW_SAMPLES,4);
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MIN OR,3);
glfwWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE);
//打开一个窗口并创建它的OpenGL上下文
window = glfwCreateWindow(1024,768,Playground,NULL,NULL);
if(window == NULL){
fprintf(stderr,无法打开GLFW窗口,如果你有一个英特尔GPU,他们不是3.3兼容,请尝试2.1版本的教程。 n);
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
//初始化GLEW
if(glewInit()!= GLEW_OK){
fprintf(stderr,无法初始化GLEW \\\
);
return -1;
}
//确保我们可以捕获正在按下的转义键
glfwSetInputMode(window,GLFW_STICKY_KEYS,GL_TRUE);
//深蓝色背景
glClearColor(0.0f,0.0f,0.4f,0.0f);
do {
//什么都不画,见教程2!
//交换缓冲区
glfwSwapBuffers(window);
glfwPollEvents();
} //检查ESC键是否被按下或窗口关闭
while(glfwGetKey(window,GLFW_KEY_ESCAPE)!= GLFW_PRESS&
glfwWindowShouldClose == 0);
//关闭OpenGL窗口并终止GLFW
glfwTerminate();
return 0;
}
这是我发现的一个关于OpenGL的教程的代码,当谈到OpenGL,但我想尝试新的东西,所以我去尝试在C + +。
我使用QtCreator这个项目。
首先,我包括了GLEW和glfw3库:
同样的glfw库文件。
然后,当我尝试编译程序时,我得到这个错误:
文本:
$ /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测试main.o -L / home / sapir / Dropbox /开发/ /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.co) :未定义对符号'glXQueryExtension'的引用
//usr/lib/x86_64-linux-gnu/mesa/libGL.so.1:添加符号时出错:命令行中缺少DSO
collect2:error:ld返回1退出状态
make:*** [测试]错误1
23:12:13:进程/ usr / bin / make退出代码2.
/部署项目Test(kit:Desktop Qt 5.4.0 GCC 64bit)
执行步骤Make
23:12:13:经过时间: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.co):未定义对符号'XConvertSelection'的引用
这是我的make文件: http ://pastebin.com/xL5Hpwsf
这是我的.pro文件: http://pastebin.com/yhkV7nn7
发现我得到的DSO错误意味着包括我实现的顺序是不正确的,导致编译失败。
所以我做的是我使用命令:
pkg-config --static --libs x11 xrandr xi xxf86vm glew glfw3
获取我需要的程序包以正确的顺序运行。
然后我编译相应的项目。
原因:)I'm trying to compile this code:
#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; }
It's a code from a tutorial I found about OpenGL, I program mostly in Java when it comes to OpenGL, but I wanted to try something new so I went to try in C++.
I'm using QtCreator for this project. At first I included GLEW and glfw3 libraries:
And the same for the glfw library file.
And then, when I try compiling the program I get this error:
In text:
$ /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.
I tired searching for an answer in forums and here, but I couldn't find anything that solved this problem. Anybody got any Ideas?
After adding
-lXxf86vm -lXrandr -lGL -lGLU -lXi
to the gcc compiler, I get a different error, which contains:
/usr/bin/ld: /home/sapir/Dropbox/Development/Computer/openGLTest/Test/../../../../../../../usr/local/lib//libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection'
This is my make file: http://pastebin.com/xL5Hpwsf
And this is my .pro file: http://pastebin.com/yhkV7nn7
解决方案Ok, after some research I found that the DSO error which I got means that the order of the includes I've implemented is incorrect and cause the compilation to fail.
So what I did is I used the command:
pkg-config --static --libs x11 xrandr xi xxf86vm glew glfw3
To get the packages I need for them to run and in the right order.
Then I compiled the project accordingly. That's it :)
这篇关于GLEW和glfw编译错误:未定义引用符号'XConvertSelection'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!