GLFW, SBCL and cl-glfw on OSX 10.5.8

sean-charles wrote on Thursday, January 14, 2010:


I really want to use the LISP binding ‘cl-glfw’ but after about a weeks effort
(in all) I still cannot get it to install from ASDF without it complaining
like this :-

Unable to load any of the alternatives:
  ((:FRAMEWORK "GLFW") (:DEFAULT "glfw") (:DEFAULT "libglfw'00

I have tried setting LD_LIBRARY_PATH which normally works (I solved a
problem using cl-sql with MySQL like this), I have tried export-ing a BASH
variable to set it and then running sbcl from the command line, I have tried
all sorts… in fact I got so annoyed I blogged abot it here:

I gave it a rest and came back a week or two later to try again, having in the
meantime started my own LISP binding around the VideoLAN LibVLC library on an
Ubuntu box and actually getting it to work and thus gaining a lot more
knowledge and insight into how CFFI works, how the whole FFI mechanism works
with SBCL but all in vain… I still cannot get it to load during the ASDF
installation phase.

Now here comes to odd / wired / baffling part… if I do the following from the
SLIME prompt it seems that it *has* managed to locate and load the library,
although I have not yet tried to call a function, I will do later.

Here is what I tried and what appeared to work:

CL-USER> (cffi:define-foreign-library libglfw
                      (:t (:default "libglfw")))
CL-USER> (cffi:use-foreign-library libglfw)

Now because that didn’t produce an error like it does during the ASDF
install/build process I am assuming it has actually done the dlopen() behind
the scenes and the library is now in memory.

What I cannot understand it shy I can do it from the REPL but it bombs from
the ASDF process, this is buggin me now because I really like the look of
using GLFW, having used cl-opengl in the past.

I have read some stuff on this board and I saw one comment about ‘static
linked version only’ being available so perhaps my problem is because the
libraries I built frmo sources are not suitable for dynamic loading? The
libraries have been installed into /usr/local/lib like so :-

-rw-r--r--   1 root  wheel     74608 26 Nov 16:51 libglfw.a
-rwxr-xr-x   1 root  wheel     67988 26 Nov 16:55 libglfw.dylib
-rwxr-xr-x   1 root  wheel     49624 26 Nov 16:52

and when I do ‘otool -tv /usr/local/lib/libglfw.dylib’ I can see the shared
library functions dyld_stub_binding_helper, __dyld_func_lookup as
expected and right after that the next function is _glfwEnable, so on the
surface of it the library looks all present and correct.

I even went as far as to write a small C program to test the library by
loading and making some simple calls into it, which works just fine and here
it is for completion of detail:

#include <stdio.h>
#include <dlfcn.h>
// Declare signatures for out functions
typedef int  (*glfwinit_sig)(void);
typedef void (*getversion_sig)(int*,int*,int*);
typedef void (*terminate_sig)(void);
typedef int (*openWindow_sig)(int,int,int,int,int,int,int,int,int);
typedef void (*setTitle_sig)(const char*);
typedef int (*getKey_sig)(int);
int main( int argc, char **argv )
  glfwinit_sig   fnGlfwInit;
  getversion_sig fnGetVersion;
  terminate_sig  fnTerminate;
  int            result, major, minor, rev, key;
  openWindow_sig  fnOpenWindow;
  setTitle_sig    fnSetTitle;
  getKey_sig      fnGetKey;
  void *libH = dlopen ( "./libglfw.dylib", RTLD_NOW );
  if ( !libH )
    printf("Library load FAILED, error: %s\n", dlerror());
  else {
    fnGlfwInit    = (glfwinit_sig)dlsym( libH, "glfwInit" );
    fnGetVersion  = (getversion_sig)dlsym( libH, "glfwGetVersion" );
    fnTerminate   = (terminate_sig)dlsym( libH, "glfwTerminate" );
    fnOpenWindow  = (openWindow_sig)dlsym( libH, "glfwOpenWindow");
    fnSetTitle    = (setTitle_sig)dlsym( libH, "glfwSetWindowTitle");
    fnGetKey      = (getKey_sig)dlsym( libH, "glfwGetKey");
    printf("init: %p, version: %p, terminate: %p\n",
    result = fnGlfwInit();
    printf("fnGlfwInit returned: %i\n", result);
    if ( result ) {
      fnGetVersion( &major, &minor, &rev );
      printf("INFO: Major: %i, Minor: %i, Revision: %i\n", major, minor, rev);
      fnOpenWindow( 300, 300,
		    0x00010001 ); // GLFW_WINDOW
      fnSetTitle("This is getting harder");
      while( 1 ) {
	if ( fnGetKey(257)) { // esc!
  return 0;

So, do any other LISP people have the solution to making cl-glfw install with
SBCL on Mac (intel) 10.5.8 please because I am going nuts right now! I
really have run out of ideas at the moment…