2015-04-05 18 views
7

Sto seguendo this tutorial. I cmake'd e make/make install'dglfw e glew perfettamente (per quanto ne so). Tuttavia, quando provo a compilare il codice di esempio ...Riferimenti non definiti Compilazione di OpenGL/glfw/glew su Ubuntu (g ++)

#define GLEW_STATIC 
#include <GL/glew.h> 
#include <GLFW/glfw3.h> 

int main() 
{ 
    glfwInit(); 
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); 
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); 

    return 0; 
} 

... usando le sue bandiere linker ...

-lGLEW -lglfw3 -lGL -lX11 -lpthread -lXrandr -lXi 

... ottengo il seguente errore:

/usr/bin/ld: /usr/local/lib/libglfw3.a(x11_init.c.o): undefined reference to symbol 'XF86VidModeQueryExtension' 
/usr/lib/x86_64-linux-gnu/libXxf86vm.so.1: error adding symbols: DSO missing from command line 

I Google l'errore e qualcuno ha suggerito di aggiungere -lXxf86vm. Si è sbarazzato dell'errore iniziale ma ha aggiunto un numero significativo in più:

/usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions': 
x11_init.c:(.text+0x1b93): undefined reference to `XineramaQueryExtension' 
x11_init.c:(.text+0x1bad): undefined reference to `XineramaIsActive' 
/usr/local/lib/libglfw3.a(x11_init.c.o): In function `_glfwCreateCursor': 
x11_init.c:(.text+0x22ee): undefined reference to `XcursorImageCreate' 
x11_init.c:(.text+0x23c5): undefined reference to `XcursorImageLoadCursor' 
x11_init.c:(.text+0x23d5): undefined reference to `XcursorImageDestroy' 
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitors': 
x11_monitor.c:(.text+0x743): undefined reference to `XineramaQueryScreens' 

Come individuare le bandiere di cui ho bisogno? Se è importante, il mio makefile è strutturato:

CC = g++ 
COMPILER_FLAGS = -std=c++11 
FILES = *.cpp 
LINKER_FLAGS = -lGLEW -lglfw3 -lGL -lX11 -lpthread -lXrandr -lXi -lXxf86vm 
OBJS = *.o 
LINUX_BIN = HelloWindow 

#Compile(output into error.txt if there is an error), link, then run 
linux: 
    $(CC) $(COMPILER_FLAGS) -c $(FILES) 2> "errors.txt" 
    $(CC) $(COMPILER_FLAGS) $(OBJS) -o $(LINUX_BIN) $(LINKER_FLAGS) 
    ./$(LINUX_BIN)   

Grazie!

+4

Per GLFW, probabilmente avete bisogno di '-lGL -lX11 -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lrt -lm' – derhass

+1

Come ha conosciuto cosa bandiere linker da usare ? – MrSnappingTurtle

+1

Osservando i simboli non risolti ... – derhass

risposta

25

Derhass era corretto. Di seguito sono le bandiere che ho usato:

-lGLEW -lglfw3 -lGL -lX11 -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lrt -lm -pthread 
+1

Sono stato anche in grado di utilizzare questa risposta quando si lavora per ottenere GLFW v2 per compilare e collegare come oggetto statico. –

+4

Ho anche dovuto aggiungere il flag '-ldl' su Ubuntu, ed è stato in grado di rimuovere i flag' -lrt' e '-lm'. Penso che tutto dipenda da quale combinazione di pacchetti/come sono installati, ma questa lista è tutto - incluso, il che è fantastico. –

Problemi correlati