# Seg Fault with GLFW Users Guide Example

**URL:** <https://discourse.glfw.org/t/seg-fault-with-glfw-users-guide-example/278>\
**Category:** support\
**Created:** [May 9, 2011, 4:58am UTC](https://discourse.glfw.org/t/seg-fault-with-glfw-users-guide-example/278 "2011-05-09T04:58:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 9, 2011, 4:58am UTC](https://discourse.glfw.org/t/seg-fault-with-glfw-users-guide-example/278/1 "2011-05-09T04:58:13Z")

</div>

**[grapedrink](https://sourceforge.net/u/grapedrink/)** wrote on [Monday, May 09, 2011](https://sourceforge.net/p/glfw/discussion/247562/thread/4f1a39da/#3327):

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 );
}
```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 9, 2011, 3:33pm UTC](https://discourse.glfw.org/t/seg-fault-with-glfw-users-guide-example/278/2 "2011-05-09T15:33:46Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Monday, May 09, 2011](https://sourceforge.net/p/glfw/discussion/247562/thread/4f1a39da/#1823):

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 9, 2011, 3:39pm UTC](https://discourse.glfw.org/t/seg-fault-with-glfw-users-guide-example/278/3 "2011-05-09T15:39:39Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Monday, May 09, 2011](https://sourceforge.net/p/glfw/discussion/247562/thread/4f1a39da/#1391):

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](http://www.glfw.org/release-2.7.html)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [May 9, 2011, 11:03pm UTC](https://discourse.glfw.org/t/seg-fault-with-glfw-users-guide-example/278/4 "2011-05-09T23:03:03Z")

</div>

**[grapedrink](https://sourceforge.net/u/grapedrink/)** wrote on [Monday, May 09, 2011](https://sourceforge.net/p/glfw/discussion/247562/thread/4f1a39da/#87e1):

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
```

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [November 16, 2026, 4:18pm UTC](https://discourse.glfw.org/t/seg-fault-with-glfw-users-guide-example/278/5 "2026-11-16T16:18:28Z")

</div>

Closed on November 16, 2026, 4:18pm UTC


