I've found that there a number of pitfalls that make getting ocamlsdl up and running on Leopard a less than straightforward experience. For the record, here are a number of fixes I found I needed to apply. I'm reconstructing the process after the fact, so I apologize if anything is missing.
0. Prepare your environment
You'll need to set up some environment variables first. I'm a tcsh
user, while the default in Leopard is bash
; hence, you'll have to modify the environment yourself depending on your shell.
- Include X11 in your executable path
libpng
andfreetype2
live inside/usr/X11
. The standard way to pass linker options is to uselibpng-config
andfreetype-config
, these are in/usr/X11/bin
. Add this to your binary path.- Fix broken Leopard linker
- Set and export
LDFLAGS
with value-dylib_file \ /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:\ /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib
(this is one long option, broken into lines for ease of reading.)
1. Get SDL
to compile
SDL
proper builds and installs without problems; however, the tests need manual intervention.
- Enter the
test
directory and ./configure. - Then manually edit
Makefile
and append $(LDFLAGS) toCFLAGS
(line 7). - Finally make and run the tests. A good test to try is testwm.
2. Compile attendant libraries
For some strange reason, SDL_image
won't find the built-in libpng
. Build and install it, together with libtiff
. Then, build and install SDL_image
, SDL_ttf
and SDL_mixer
. Everything should work; if not, check that the variables above are correctly set in your session's environment.
3. Compile ocamlsdl
I assume you're using ocamlfind
; if not, you'll probably not find trouble with the last step.
- Start by doing ./configure; it should say that it'll build
SDL_image
,SDL_ttf
andSDL_mixer
. - Then, edit
makefile.config.gcc
so that lines 29 and 30 read -framework Cocoa instead of the original -Wl,-framework,Cocoa. - Also, edit
src/Makefile
so that line 89 reads $(RANLIB) $$($(OCAMLFIND) query sdl)/*.$(A) instead of the original $(RANLIB) $$($(OCAMLFIND) printconf destdir)/*.$(A). - Finaly make it.
If you've installed a previous version of ocamlsdl
and you're using ocamlfind
, you'll need to manually remove the installation directory (ocamlfind query sdl) prior to sudo make install.
3. Test ocamlsdl
I've found a great "hello world"-type of walk-through., but it needs some tweaking for MacOS X, as the ocamlsdl
README explains. Use the following Makefile
:
RESULT = testsdl_1 SOURCES = testsdl_1.ml PACKS = bigarray sdl OCAMLBLDFLAGS = -custom include OCamlMakefile
and make sure that the example built with make nc (native code) and make (bytecode) both work. Again, I assume you're using ocamlfind
.
Good luck!
2 comments:
I've followed all the steps and I'm sure my installations are correct, but it looks as if there's something wrong with OCamlMakefile. Here's the error that I'm getting:
make[1]: *** No rule to make target `testsdl_1.cmi', needed by `testsdl_1'. Stop.
make: *** [byte-code] Error 2
I'll admit I'm not familiar with ocamlc and ocamlopt, maybe using OCamlMakefile for this is a little overkill?
My problem was my ocamlsdl installation, I had installed ocamlsdl before installing ocamlfind. I hadn't followed the steps quite like I said I had.
Post a Comment