The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Compiling SDL_image for NaCl
ollika


Joined: 28 Nov 2013
Posts: 18
I tried compiling my SDL app for NaCl (mostly just for fun).

I was able to get the SDL test app running on Chrome, but I could not find instructions to compile SDL_image for NaCl to get my own app to compile.

Are there instructions somewhere that I could follow?
Compiling SDL_image for NaCl
slvn


Joined: 06 Oct 2012
Posts: 88
Hello,

SDL_image, ttf and mixer are working with NaCL.
only a small patch need to be done on their files "config.sub"

(Like on SDL lib, see https://hg.libsdl.org/SDL/rev/ae720d61d14d)

I guess it should be somehow generated, but I don't know how.

Cheers,
Sylvain


On Mon, Jul 7, 2014 at 10:18 AM, ollika wrote:
Quote:
I tried compiling my SDL app for NaCl (mostly just for fun).

I was able to get the SDL test app running on Chrome, but I could not find
instructions to compile SDL_image for NaCl to get my own app to compile.

Are there instructions somewhere that I could follow?

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




--
Sylvain Becker
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Compiling SDL_image for NaCl
Sam Lantinga


Joined: 10 Sep 2009
Posts: 1765
I just updated SDL_image, SDL_mixer, SDL_net, and SDL_ttf with the nacl config.sub changes.

Thanks!


On Mon, Jul 7, 2014 at 2:50 AM, Sylvain Becker wrote:
Quote:
Hello,

SDL_image, ttf and mixer are working with NaCL.
only a small patch need to be done on their files "config.sub"

(Like on SDL lib, see https://hg.libsdl.org/SDL/rev/ae720d61d14d)

I guess it should be somehow generated, but I don't know how.

Cheers,
Sylvain


On Mon, Jul 7, 2014 at 10:18 AM, ollika wrote:
Quote:
I tried compiling my SDL app for NaCl (mostly just for fun).

I was able to get the SDL test app running on Chrome, but I could not find
instructions to compile SDL_image for NaCl to get my own app to compile.

Are there instructions somewhere that I could follow?



Quote:
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




--
Sylvain Becker
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
ollika


Joined: 28 Nov 2013
Posts: 18
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):

1) 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

2) 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

3) 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=<path to your sdl>/SDL
export CFLAGS="-I$NACL_SDK_ROOT/include -I$NACL_SDK_ROOT/include/pnacl -I<path to your sdl>/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.

4) 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

5) 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.
Compiling SDL_image for NaCl
gabomdq


Joined: 28 Jul 2011
Posts: 495
Location: Argentina
Thanks for sharing! You can open Chrome's Dev Console and see if you get any information there before the crash, and you can also use GDB's remote debugging (it's a PITA to get right though Wink ): https://developer.chrome.com/native-client/devguide/devcycle/debugging


2014-07-08 10:54 GMT-03:00 ollika:
Quote:
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):

1) 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

2) 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

3) 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.

4) 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

5) 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.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org





--
Gabriel.
Compiling SDL_image for NaCl
slvn


Joined: 06 Oct 2012
Posts: 88
Ollika,

On my side, there was almost not modification to build my app for NaCl.
The most annoying trouble was chrome on linux that wasn't working correctly.

I had to use the "google-chrome-beta" package.
I would double-check that the "test examples" are working !

Cheers,
Sylvain




On Tue, Jul 8, 2014 at 4:18 PM, Gabriel Jacobo wrote:
Quote:
Thanks for sharing! You can open Chrome's Dev Console and see if you get any
information there before the crash, and you can also use GDB's remote
debugging (it's a PITA to get right though Wink ):
https://developer.chrome.com/native-client/devguide/devcycle/debugging


2014-07-08 10:54 GMT-03:00 ollika:
Quote:

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):

1) 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

2) 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

3) 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.

4) 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

5) 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.

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




--
Gabriel.

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




--
Sylvain Becker
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org