Glfw does not compile under Ubuntu 8.04 :(

nobody wrote on Saturday, June 21, 2008:


I used glfw for Windows Vista and it worked perfectly. Now I switched
to Ubuntu 8.04 and want to continue develop under this platform.
But I am not able to compile my programs with glfw…I am new to Linux :frowning:

Here are some Infos, which will maybe help you to help me :slight_smile:

- downloaded glfw 2.6 source

- installed newest nvidia-driver (NVIDIA-Linux-x86-173.14.05-pkg1)

- installed the package "libglu1-mesa-dev" (For the GLU-Library)

- Then I created the shared and static glfw library with:
sudo make x11
sudo make x11-install

- All worked fine: Now I have the following important libs and Headerfiles:

/usr/include/GL ls
	glext.h  gl.h  gl\_mangle.h  glu.h  glu\_mangle.h  glxext.h  glx.h  glx\_mangle.h

/usr/local/lib ls

- When I type glxinfo all seems ok:
/usr/local/lib glxinfo
name of display: :0.0
display: :0 screen: 0
direct rendering: Yes
server glx vendor string: NVIDIA Corporation
server glx version string: 1.4
GLX version: 1.3
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce 8500 GT/PCI/SSE2
OpenGL version string: 2.1.2 NVIDIA 173.14.05

- Then I wrote some sample Test Programm called test.c:


#include <stdlib.h> // For malloc() etc.
#include <stdio.h> // For printf(), fopen() etc.
#include <math.h> // For sin(), cos() etc.
#include <GL/glfw.h> // For GLFW, OpenGL and GLU

void Draw( void )
int width, height; // Window dimensions
double t; // Time (in seconds)

// Get current time
t = glfwGetTime\(\);

  // Get window size
  glfwGetWindowSize\( &amp;width, &amp;height \);

  // Make sure that height is non-zero to avoid division by zero
  height = height &lt; 1 ? 1 : height;

  // Set viewport
  glViewport\( 0, 0, width, height \);

  // Clear color and depht buffers
  glClearColor\( 0.0f, 0.0f, 0.0f, 0.0f \);

  // Set up projection matrix
  glMatrixMode\( GL\_PROJECTION \);    // Select projection matrix
  glLoadIdentity\(\);                 // Start with an identity matrix
  gluPerspective\(                   // Set perspective view
      65.0,                         // Field of view = 65 degrees
      \(double\)width/\(double\)height, // Window aspect \(assumes square pixels\)
      1.0,                          // Near Z clipping plane
      100.0                         // Far Z clippling plane

  // Set up modelview matrix
  glMatrixMode\( GL\_MODELVIEW \);     // Select modelview matrix
  glLoadIdentity\(\);                 // Start with an identity matrix
  gluLookAt\(                        // Set camera position and orientation
      0.0, 0.0, 10.0,               // Camera position \(x,y,z\)
      0.0, 0.0, 0.0,                // View point \(x,y,z\)
      0.0, 1.0, 0.0                 // Up-vector \(x,y,z\)

  // Here is where actual OpenGL rendering calls would begin...


int main( int argc, char **argv )
int ok; // Flag telling if the window was opened
int running; // Flag telling if the program is running

  // Initialize GLFW

  // Open window
  ok = glfwOpenWindow\(
      640, 480,          // Width and height of window
      8, 8, 8,           // Number of red, green, and blue bits for color buffer
      8,                 // Number of bits for alpha buffer
      24,                // Number of bits for depth buffer \(Z-buffer\)
      0,                 // Number of bits for stencil buffer
      GLFW\_WINDOW        // We want a desktop window \(could be GLFW\_FULLSCREEN\)

  // If we could not open a window, exit now
  if\( \!ok \)
      return 0;

  // Set window title
  glfwSetWindowTitle\( &quot;My OpenGL program&quot; \);

  // Enable sticky keys
  glfwEnable\( GLFW\_STICKY\_KEYS \);

  // Main rendering loop
      // Call our rendering function

      // Swap front and back buffers \(we use a double buffered display\)

      // Check if the escape key was pressed, or if the window was closed
      running = \!glfwGetKey\( GLFW\_KEY\_ESC \) &amp;&amp;
                glfwGetWindowParam\( GLFW\_OPENED \);
  while\( running \);

  // Terminate GLFW

  // Exit program
  return 0;


- For the compiling I used the following command:

gcc test.c -o test.exe -lglfw -lGL -lGLU -lX11 -lpthread -lm

- then I got this :frowning:

/usr/local/lib/libglfw.a(x11_init.o): In function `_glfwPlatformInit’:
x11_init.c:(.text+0xea): undefined reference to `XRRQueryExtension’
/usr/local/lib/libglfw.a(x11_window.o): In function `_glfwPlatformRefreshWindowParams’:
x11_window.c:(.text+0x805): undefined reference to `XRRGetScreenInfo’
x11_window.c:(.text+0x80f): undefined reference to `XRRConfigCurrentRate’
x11_window.c:(.text+0x81d): undefined reference to `XRRFreeScreenConfigInfo’
/usr/local/lib/libglfw.a(x11_window.o): In function `_glfwPlatformCloseWindow’:
x11_window.c:(.text+0xb7f): undefined reference to `XRRGetScreenInfo’
x11_window.c:(.text+0xba2): undefined reference to `XRRSetScreenConfig’
x11_window.c:(.text+0xbab): undefined reference to `XRRFreeScreenConfigInfo’
/usr/local/lib/libglfw.a(x11_window.o): In function `_glfwPlatformPollEvents’:
x11_window.c:(.text+0x1158): undefined reference to `XRRUpdateConfiguration’
/usr/local/lib/libglfw.a(x11_window.o): In function `_glfwPlatformOpenWindow’:
x11_window.c:(.text+0x1fb3): undefined reference to `XRRSelectInput’
/usr/local/lib/libglfw.a(x11_fullscreen.o): In function `_glfwPlatformGetVideoModes’:
x11_fullscreen.c:(.text+0x1b0): undefined reference to `XRRGetScreenInfo’
x11_fullscreen.c:(.text+0x1c1): undefined reference to `XRRConfigSizes’
x11_fullscreen.c:(.text+0x1ff): undefined reference to `XRRFreeScreenConfigInfo’
/usr/local/lib/libglfw.a(x11_fullscreen.o): In function `_glfwSetVideoModeMODE’:
x11_fullscreen.c:(.text+0x308): undefined reference to `XRRGetScreenInfo’
x11_fullscreen.c:(.text+0x323): undefined reference to `XRRConfigCurrentConfiguration’
x11_fullscreen.c:(.text+0x373): undefined reference to `XRRSetScreenConfigAndRate’
x11_fullscreen.c:(.text+0x38b): undefined reference to `XRRSetScreenConfig’
/usr/local/lib/libglfw.a(x11_fullscreen.o): In function `_glfwGetClosestVideoMode’:
x11_fullscreen.c:(.text+0x3dc): undefined reference to `XRRGetScreenInfo’
x11_fullscreen.c:(.text+0x3ed): undefined reference to `XRRConfigSizes’
x11_fullscreen.c:(.text+0x466): undefined reference to `XRRConfigRates’
x11_fullscreen.c:(.text+0x4b3): undefined reference to `XRRFreeScreenConfigInfo’
/usr/local/lib/libglfw.a(x11_fullscreen.o): In function `_glfwSetVideoModeMODE’:
x11_fullscreen.c:(.text+0x39d): undefined reference to `XRRFreeScreenConfigInfo’

What I have done wrong ?

I have tried also tried to install the package "libxrandr-dev" but I had also the newest version already installed.

Can somebody plz help me to set the correct compile-Parameter ?

thanx und greetz


nobody wrote on Saturday, June 21, 2008:

Hey…no I have solved it :slight_smile:

The right command-line is the following :slight_smile: I forgot the -lxandr :slight_smile:

gcc test.c -o test.exe -lglfw -lGL -lGLU -lX11 -lpthread -lXrandr -lm

Thanx and Greetz