Ocamlsdl mac

From Seoushi Games

Jump to: navigation, search

Contents

Introduction

So I finally got ocaml, ocamlsdl and OS X to play nicely. It builds with the sdl.framework from http://www.libsdl.org and uses cocoa without spiting out any error, best of all it doesn't crash. I hope that the follow proves useful to some people that were trying to get this to work.

How I did it

Upon searching for an answer I came upon a post saying that I needed to add the following code to sdl_stub.c

int main(int argc, char **argv)
{
caml_main(argv);
return 0;
}

While they were right that wasn't the whole truth and I got many compile errors. I needed to change the makefile to include the sdl and cocoa frameworks along with some other linker options.

Later on I realized that the function nil in sdl_stub.c conflicted with cocoa's definition of nil so I changed that function and all references to sdlstub_nil.

The last thing I had to do was compile sdl_stub.c with SDLMain.m to produce libocamlsdl.a, now I had a complete working native version of ocamlsdl for OS X.

The Changes

Since the above part might help some it won't help all so I'm including a full tarball of my project directory. All you have to do is type "make" in the top level directory and all is well and dandy. Compiling applications is like you would suspect for linux (example "ocamlopt.opt -o test sdl.cmxa test.cmx" ).

Differences

The files I have changed include a custom makefile, minor edits to sdl_stub.c and the inclusion of SDLMain.m and SDLMain.h, both SDLMain files can be grabbed from the xcode template that comes with the SDL.framework from http://www.libsdl.org.

What doesn't work

For some reason sdl_mixer doesn't like to compile, if someone fixes up the error then let me know and I can change it.

Download

Here is my full project directory, if you have issues with it you can email me but it's most likely a path problem of some kind so check the makefile first and make sure the paths are correct for your setup. As stated previously just issue "make" in the top-level directory from the command line and you should be in business. Ocamlsdl project zip