Thanks!
I got everything to compile with some fiddling. My app is currently crashing on load, but I’m sure that it’s my fault (because I haven’t looked into how to load files files with nacl yet).
I thought I’d put some notes from my adventures so far.
Obviously all this needs to be cleaned up and automated, but here is a quick and dirty way to compile SDL and SDL_image for PNaCl (on linux):
-
Preparing NACL
Download and install nacl (I installed nacl to ~/nacl_sdk/)
Set the environment var that points to the nacl installation:
export NACL_SDK_ROOT=/home/me/nacl_sdk/pepper_35
-
Compiling SDL (in your SDL dir):
export CFLAGS="-I$NACL_SDK_ROOT/include -I$NACL_SDK_ROOT/include/pnacl"
export CC="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-clang"
export AR="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-ar"
export LD="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-ar"
export RANLIB="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-ranlib"
./configure --host=pnacl
make
-
Compiling SDL_image (in your SDL_image dir):
Nacl comes with precompiled libz, libpng and libjpeg but they are in a separate “ports” folder.
I added the paths manually here to make configure find them. For some reason adding the path to CFLAGS did not work, so I added it directly to the command. Also I had to add LIBS=-lm to get configure to accept libpng.
In addition SDL_image needs to know about SDL.
export SDL2_CONFIG=/SDL
export CFLAGS="-I$NACL_SDK_ROOT/include -I$NACL_SDK_ROOT/include/pnacl -I/SDL/include"
export LDFLAGS="-L$NACL_SDK_ROOT/ports/lib/newlib_pnacl/Release"
export CC="$NACL_SDK_ROOT/toolchain/linux_pnacl/bin/pnacl-clang -I$NACL_SDK_ROOT/ports/include"
export LIBS=-lm
./configure --host=pnacl
make
Compiling the test program for SDL image fails, but I got the libSDL2_image.a out OK so it doesn’t really matter.
- Compiling my app
I copied the test program from SDL/test/nacl/ to myproject/nacl/.
I created myproject/nacl/lib and copied all the SDL libs there (libSDL2.a libSDL2_image.a libSDL2main.a)
I did some edits to the Makefile copied from sdl test:
Point NACL_SDK_ROOT to your nacl installation:
NACL_SDK_ROOT ?= /home/suikkari/nacl/nacl_sdk/pepper_35
I added the image libs (and removed test). This order worked for me (order matters):
LIBS = SDL2_image SDL2 ppapi_simple SDL2main SDL2 png tiff jpeg z $(DEPS) ppapi_gles2 ppapi_cpp ppapi pthread
I created a new variable containing the extra libs:
EXTRA_LIB_PATHS = -L$(NACL_SDK_ROOT)/ports/lib/newlib_pnacl/$(CONFIG) -L./lib
and modified the linking line a bit to use it:
$(call LOG,LINK,$$@,$(PNACL_LINK) -o $$@ $(2) $(PNACL_LDFLAGS) $(foreach path,$(5),-L$(path)/pnacl/$(CONFIG)) $(EXTRA_LIB_PATHS) $(foreach lib,$(3),-l$(lib)) $(6))
(There must be a better way to define library search paths. Surely. Also I assume there is some way to nicely link to the ports libs that are included with nacl, but I did not find it with a quick search.):
Now replace the sources list with your source files and run make (Assuming the same environment variables that were defined for compiling SDL_image are still defined):
make
- Done. There should be a pexe file somewhere in myproject/nacl/pnacl.
There are still some steps to see the app in your browser but those should be easier to figure out. Like I said, my app is still crashing on startup. So I’m not 100% sure if this works, but I’m pretty sure it should. I could try with some simpler program, but I haven’t had the time to do that yet.