[英]CodeBlocks - “undefined reference to symbol '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 )
{
// 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庫:
對於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 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'
這是我的make文件: http : //pastebin.com/xL5Hpwsf
這是我的.pro文件: http : //pastebin.com/yhkV7nn7
好吧,經過一些研究后我發現我得到的DSO錯誤意味着我實現的包含順序不正確並導致編譯失敗。
所以我做的是我使用命令:
pkg-config --static --libs x11 xrandr xi xxf86vm glew glfw3
獲取我需要的包以便以正確的順序運行。
然后我相應地編譯了項目。 而已 :)
我從Irrlicht 3D編譯示例時得到了相同的錯誤“未定義的符號'XConvertSelection''參考,通過添加”-lX11“解決。
然后我得到錯誤“未定義引用符號'XF86VidModeGetGamma'”,通過添加“-lXxf86vm”解決
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.