Menu

Seg Fault with GLFW Users Guide Example

Using GLFW
2011-05-09
2012-11-08
  • grape drink

    grape drink - 2011-05-09

    Hi I'm getting a Segmentation Fault with the example in the GLFW 2.7 Users
    Guide in section 2.4 titled a "Minimal GLFW Application". I'm Mac OSX 10.6
    with Xcode 3.2.5 installed.
    I compiled GLFW 2.7 with "make cocoa-install" and then copied libglfw.dylib
    over to /usr/local/lib

    I'm building with:

    g++ -Wall -o test test.cpp -I glfw-2.7 -Lglfw-2.7/lib/cocoa -lglfw -L/usr/X11/lib -lGL
    

    I run with: ./test
    and the code seg faults and only print out my "print 1" line.
    Any ideas on what I'm doing wrong? I'm suspicious of the GL libraries or
    something….

    #include <GL/glfw.h>
    #include <stdlib.h>
    #include <iostream>
    using std::cout;
    int main( void ) {
      int running = GL_TRUE;
      // Initialize GLFW
      if( !glfwInit() )
        exit( EXIT_FAILURE );
      // Open an OpenGL window
      if( !glfwOpenWindow( 300,300, 0,0,0,0,0,0, GLFW_WINDOW ) ) {
        glfwTerminate();
        exit( EXIT_FAILURE );
      }
      // Main loop
      while( running ) {
     [b]   cout<<"print 1\n"; [/b]
       // OpenGL rendering goes here...
        glClear( GL_COLOR_BUFFER_BIT );
      cout<<"print 2\n";  
      // Swap front and back rendering buffers
        glfwSwapBuffers();
        // Check if ESC key was pressed or window was closed
        running = !glfwGetKey( GLFW_KEY_ESC ) && glfwGetWindowParam( GLFW_OPENED );
      }
      // Close window and terminate GLFW
      glfwTerminate();
      // Exit program
      exit( EXIT_SUCCESS );
    }
    
     
  • elmindreda

    elmindreda - 2011-05-09

    Thank you for an exemplary bug report. I'll verify this asap.

     
  • elmindreda

    elmindreda - 2011-05-09

    The problem is that you are linking against the X11 libraries while using the
    Cocoa port of GLFW. Information on the correct use of GLFW on Mac OS X is in
    section 4.2.5 of readme.html, also available here:
    http://www.glfw.org/release-2.7.html

     
  • grape drink

    grape drink - 2011-05-09

    Thanks elmindreda!

    I changed build line to include "-framework Cocoa -framework OpenGL" and
    dropped the additional GL library as the documentation said.

    My corrected build line is now:

    g++ -Wall -o test test.cpp -I glfw-2.7 -Lglfw-2.7/lib/cocoa -lglfw -framework Cocoa -framework OpenGL