3

I'm trying to compile glfw as static link on Linux Mint (based on Ubuntu 10.04) using GCC 4.4.3.

Inside my project directory i got "external/glfw" which contains glfw 2.7.1 source. I've compiled it by running "make x11-install" which gives:

  • /usr/local/include/GL/glfw.h
  • /usr/local/lib/libglfw.a
  • /usr/local/lib/pkgconfig/libglfw.pc

i also got this simple code in test.c:

#include <stdio.h>
#include <stdlib.h>
#include "external/glfw/include/GL/glfw.h"

int main( int argc, char const* argv[] )
{
    if( !glfwInit() ){
        fprintf( stderr, "glfwInit Failed\n" );
    }

    glfwOpenWindowHint( GLFW_FSAA_SAMPLES, 4 );
    glfwOpenWindowHint( GLFW_OPENGL_VERSION_MAJOR, 3 );
    glfwOpenWindowHint( GLFW_OPENGL_VERSION_MINOR, 1 );
    glfwOpenWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );

    // Open a window and create its OpenGL context
    if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW )){
        fprintf( stderr, "glfwOpenWindow failed\n" );
        glfwTerminate();
        return -1;
    }

    return 0;
}

i'm trying to compile glfw as static link and compiled the code using gcc with flags:

/usr/bin/gcc `pkg-config --cflags libglfw` -o test test.c \
`pkg-config --libs libglfw` -lXrandr -lX11 -lGLU -lGL -pthread -lm

and it doesn't give me any error. but when i try to execute the binary it shows that i've failed to call glfwOpenWindow.

could any one help me please? thank you for your time guys!

cheers!

P

EDIT 1: I think the problem lies with the linking process and not the code. Because if i have libglfw2 and libglfw-dev installed (ubuntu packages), then the executable runs just fine. What i want here is to have glfw statically linked and not to rely on distro package share libs for the binary to run.

EDIT 2 as per datenwolf suggestion i tried to debug with gdb. i never use gdb before but i use perl debugger a lot. somehow they share a lot of similarities. i recompile glfw and my test.c with -ggdb.

flowing with gdb it shows that my code goes into glfwOpenWindow() which is in "window.c" in glfw source code. since i'm new to gdb i don't know how to evaluate expression or get the value of variables. based on quick search on google all i know is "whatis" to see the date type. but i think my code stops when it reached line 484 in "window.c"

if( wndconfig.glProfile &&
    ( wndconfig.glMajor < 3 || ( wndconfig.glMajor == 3 && wndconfig.glMinor < 2 ) ) )
{
    // Context profiles are only defined for OpenGL version 3.2 and above
    return GL_FALSE;
}

now i'm not sure how come using static link glfw thinks i'm not on OpenGL 3.2 and above, while having libglfw2 installed it works just fine?

thanks for your help guys! especially datenwolf!

EDIT 3 Thanks for the help guys. After some help from people in stackoverflow and old nabble I manage to write it down what needs to be done to statically linked GLFW and GLEW and put it on http://www.phacks.net/static-compile-glfw-and-glew/

2 Answers 2

2

So your error is that the call to glfwOpenWindow failed? No unresolved symbol or shared object not found messages before even main() gets called? Then you successfully linked against GLFW statically.

I think your problem lies in the parameters you pass to glfwOpenWindow:

glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW )

So you're requesting zero red, green or blue bits per channel, but 32 depth bits. I doubt your system supports that. I'd try

glfwOpenWindow( 1024, 768, 8,8,8,0, 24, 8, GLFW_WINDOW )

that's what most systems support well.

8
  • thanks for your answer! i don't think the problem lies with the code because if i have libglfw2 and libglfw-dev installed, the executable runs just fine. i think the problem lies with the linkin process Aug 22, 2011 at 4:36
  • @pixelblender: So what output does executing your program produce if those libraries are not installed?
    – datenwolf
    Aug 22, 2011 at 6:51
  • it throws "glfwOpenWindow failed" which is printed because it failed to call glfwOpenWindow Aug 22, 2011 at 8:48
  • @pixelblender: This message just tells you that the call that's suppoed to be glfwOpenWindow returned 0. The call definitely didn't fail because it was executed; calling into an unresolved symbol would most likely crash the process. How to debug this: Recompile your static GLFW with debug information enabled, the same with your own program. Start it in a debugger; I recommend the GDB frontend Data Display Debugger (ddd). Put a breakpoint on the call of glfwOpenWindow and single step from there, decending into functions.
    – datenwolf
    Aug 22, 2011 at 9:50
  • i've updated my findings. do you have any idea why glfw thinks i'm not on opengl 3.2 and above? cheers datenwolf! Aug 22, 2011 at 13:02
0

Your example program requests OpenGL 3.1 and a context profile. Profiles are only defined for OpenGL 3.2 and above, which is most likely why glfwOpenWindow fails in this case. To fix this, either request a version above or equal to 3.2, or remove the request for a context profile.

For more information about modern OpenGL context creation with GLX, upon which this part of GLFW is a thin layer, see http://www.opengl.org/registry/specs/ARB/glx_create_context.txt .

1
  • Also, using zeros for the various bit depths to glfwOpenWindow is just fine (and is in fact done by most GLFW test programs).
    – elmindreda
    Sep 9, 2011 at 1:38

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.