Compile and run mesa on bluehost web server

Alec Jacobson

October 07, 2012

weblog/

I want to use the off-screen renderer of Mesa in a php script on my blue host served website. Compiling Mesa on my mac was dead simple (sudo port install mesa), but doing it on the linux server without root access or repositories was a bit tricky. Here's how I finally got it to work. Download and compile llvm, if it's not around already. I found that version 3.1 didn't play nicely with Mesa but 3.0 did. LLVM installed smoothly.
./configure --prefix=[INSTALL_PREFIX]
make -j5
make install
Next, grab the latest glproto headers. As far as I can tell, there is nothing to compile as only headers are needed. Download mesa, unzip and compile using the following:
% Set up glproto headers
export GLPROTO_LIBS=../glproto-1.4.16/;
export GLPROTO_CFLAGS=../glproto-1.4.16/;
% configure, disabling DRI support (i.e. graphics card support)
./configure --prefix=[INSTALL_PREFIX] --disable-driglx-direct --enable-xlib-glx --enable-osmesa --disable-dri
make -j5
make install
Then I got the Mesa demos and made sure I could compile src/osdemos/osdemo.c:
gcc -o osdemo osdemo.c -I[INSTALL_PREFIX]/include -L[INSTALL_PREFIX]/lib -lOSMesa -lGLU
Upon running osdemo, you might see:
./osdemo: error while loading shared libraries: libOSMesa.so.8: cannot open shared object file: No such file or directory
But this is fixed by adding you library install path to the LD_LIBRARY_PATH variable:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:[INSTALL_PATH]/lib/
or in php:
putenv("LD_LIBRARY_PATH=".$_ENV["LD_LIBRARY_PATH"].":[INSTALL_PATH]/lib/");
If it works then you can run the program with:
./osdemo foo.tga
and produce an image like: output of osdemo of mesa demos running on web server