# Best approach to compile SDL for multiple targets?

**URL:** <https://discourse.libsdl.org/t/best-approach-to-compile-sdl-for-multiple-targets/19060>\
**Category:** SDL Development\
**Created:** [August 14, 2012, 7:05pm UTC](https://discourse.libsdl.org/t/best-approach-to-compile-sdl-for-multiple-targets/19060 "2012-08-14T19:05:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![singmajesty](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/singmajesty/32/2750_2.png) [@singmajesty](https://discourse.libsdl.org/u/singmajesty)\
**Post date:** [August 14, 2012, 7:05pm UTC](https://discourse.libsdl.org/t/best-approach-to-compile-sdl-for-multiple-targets/19060/1 "2012-08-14T19:05:33Z")

</div>

Hi!

I am a lead developer for NME, an open-source, cross-platform framework for:

- Windows
- Mac
- Linux
- iOS
- Android
- BlackBerry
- Flash
- HTML5

I’ve been thinking of moving to SDL 2.0 for some time. However, the traditional “configure; make; make install” approach seems to work best if you only want the library on your local machine. I need to be able to compile static versions of SDL for each support native target.

We use our own staging for iOS and Android currently, but I would like to look at what these targets would be like, standardizing on SDL. BlackBerry and webOS use SDL currently. I probably would like at either continuing to support SDL 1.2 for these targets, or probably helping work on BlackBerry support in SDL 2.0.

Flash and HTML5 probably sound like they come from left-field, but the framework uses Haxe, which can compile to C++, SWF and Javascript, so wild as it is, they are all related.

My question is which way you recommend to build SDL for all platforms. We have our own make script that helps build all the native dependencies for each target platform. I am concerned that “configure; make” will result in a binary that is designed for the target machine (like OS X 10.8) rather than a sensible minimum version, or that trying to configure SDL multiple times for separate targets, in the same directory, will turn out poorly.

Just a few pointers should help, I apologize if this seems like an obvious question. I’m not as involved on the lower level

---

<div class="post-metadata">

**Author:** ![Gabriel\_Jacobo](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/gabriel_jacobo/32/1968_2.png) [@Gabriel\_Jacobo](https://discourse.libsdl.org/u/Gabriel_Jacobo)\
**Post date:** [August 14, 2012, 7:27pm UTC](https://discourse.libsdl.org/t/best-approach-to-compile-sdl-for-multiple-targets/19060/2 "2012-08-14T19:27:37Z")

</div>

2012/8/14 Joshua Granick

> Hi!
> 
> I am a lead developer for NME, an open-source, cross-platform framework  
> for:
> 
> - Windows
> - Mac
> - Linux
> - iOS
> - Android
> - BlackBerry
> - Flash
> - HTML5
> 
> I’ve been thinking of moving to SDL 2.0 for some time. However, the  
> traditional “configure; make; make install” approach seems to work best if  
> you only want the library on your local machine. I need to be able to  
> compile static versions of SDL for each support native target.
> 
> We use our own staging for iOS and Android currently, but I would like to  
> look at what these targets would be like, standardizing on SDL. BlackBerry  
> and webOS use SDL currently. I probably would like at either continuing to  
> support SDL 1.2 for these targets, or probably helping work on BlackBerry  
> support in SDL 2.0.
> 
> Flash and HTML5 probably sound like they come from left-field, but the  
> framework uses Haxe, which can compile to C++, SWF and Javascript, so wild  
> as it is, they are all related.
> 
> My question is which way you recommend to build SDL for all platforms. We  
> have our own make script that helps build all the native dependencies for  
> each target platform. I am concerned that “configure; make” will result in  
> a binary that is designed for the target machine (like OS X 10.8) rather  
> than a sensible minimum version, or that trying to configure SDL multiple  
> times for separate targets, in the same directory, will turn out poorly.
> 
> Just a few pointers should help, I apologize if this seems like an obvious  
> question. I’m not as involved on the lower level  
> \_\_\_\_\_\_\_\_\_\_\_\_\__ **\*\*** _

Hi! First of all let me express my admiration for what Haxe and Haxe NME  
do, I found out about it a few months ago and it really impressed me to the  
point where I almost left my own project to join the Haxe bandwagon. For  
now, I haven’t jumped ship, but I can give you a few pointers that came out  
of my experience doing a project that has several points of contact with  
Haxe NME, my Python/Cython based engine Ignifuga ([ignifuga.org](http://ignifuga.org)).

I compile SDL2 for Windows/Linux/Android/iOS and OS X. Sadly the build  
system I use is not as uniform as I’d like and it abuses sed in some places  
(you can see the code here:  
[https://bitbucket.org/gabomdq/ignifuga/src/fc9cbbce5a78/tools/modules/sdl](https://bitbucket.org/gabomdq/ignifuga/src/fc9cbbce5a78/tools/modules/sdl))  
but these are a few lessons I learned…

- With the correct environment variables, you can cross compile and  
statically link from Linux for Windows (using Mingw) and Linux itself. The  
only snag I’ve encountered is that statically linking libdl produces a  
segfault when loading Nvidia’s OpenGL stuff dynamically. So, I link to  
libdl dynamically.
- Android requires a bit of file rearranging (you have an Android project  
skeleton that’s included with SDL and you use ndk-build to build it), but I  
believe it’s possible to use the configure;make procedure here as well, if  
you set the correct environment variables and copy the correct SDL\_config.h  
file after configuring, but I haven’t tried that method. So, under Linux  
and OS X, I build SDL using ndk-build and the Android project template. The  
process produces a binary that works on Android API Level 5 and up if I  
recall correctly.
- For OS X you can build it under OS X (no cross compiling AFAIK), and  
there’s an included script (build-scripts/fatbuild.sh) which will generate  
a static fat binary for i386, x64 and PPC, with support for OS X 10.6 and  
higher.
- For iOS (only cross compiling from OS X), based on my work for Ignifuga I  
recently added a iosbuild.sh script which will do what fatbuild.sh does but  
for iOS use. It will generate a static binary for armv6, armv7 and i386  
(for simulator use)
- Both fatbuild.sh and iosbuild.sh show examples of how to configure for  
multiple targets using the same code base and different build directories.–  
Gabriel.

---

<div class="post-metadata">

**Author:** ![Fabio\_Panettieri](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/f/a3d4f5/32.png) [@Fabio\_Panettieri](https://discourse.libsdl.org/u/Fabio_Panettieri)\
**Post date:** [August 14, 2012, 7:32pm UTC](https://discourse.libsdl.org/t/best-approach-to-compile-sdl-for-multiple-targets/19060/3 "2012-08-14T19:32:55Z")

</div>

Hi I’m pretty interested on this kind of guidelines too!

I’ve worked with SDL 1.2 in the past, and starting a new game right  
now, and I was thinking on using SDL 2.0 from the hg repo, as the  
functionality I’ll need now is minimal and I think it’s all working.

In the past I’ve used Makefiles for each target platform, that compile  
dependencies (including a call to compile SDL) and the game itself.  
But probably it’s a very bad (manual) way to do this, so any  
recommendation will be appreciated.

2012/8/14 Joshua Granick :

> My question is which way you recommend to build SDL for all platforms. We  
> have our own make script that helps build all the native dependencies for  
> each target platform. I am concerned that “configure; make” will result in a  
> binary that is designed for the target machine (like OS X 10.8) rather than  
> a sensible minimum version, or that trying to configure SDL multiple times  
> for separate targets, in the same directory, will turn out poorly.

For this, I have used build directories for each target platform, that  
also includes the code that change from platform to platform.  
Then I just cd to that directory and run make.\>

> Just a few pointers should help, I apologize if this seems like an obvious  
> question. I’m not as involved on the lower level

---

<div class="post-metadata">

**Author:** ![Jared\_Maddox](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/8baadc/32.png) [@Jared\_Maddox](https://discourse.libsdl.org/u/Jared_Maddox)\
**Post date:** [August 15, 2012, 3:34am UTC](https://discourse.libsdl.org/t/best-approach-to-compile-sdl-for-multiple-targets/19060/4 "2012-08-15T03:34:16Z")

</div>

> Message-ID:  
> \<CAEXb9uG5uUyxG5Fv9uzmifLbuC=hUGJWNdzwbfJjF=bNYmit3Q at [mail.gmail.com](http://mail.gmail.com)\>  
> Content-Type: text/plain; charset=ISO-8859-1
> 
> Hi I’m pretty interested on this kind of guidelines too!
> 
> I’ve worked with SDL 1.2 in the past, and starting a new game right  
> now, and I was thinking on using SDL 2.0 from the hg repo, as the  
> functionality I’ll need now is minimal and I think it’s all working.
> 
> In the past I’ve used Makefiles for each target platform, that compile  
> dependencies (including a call to compile SDL) and the game itself.  
> But probably it’s a very bad (manual) way to do this, so any  
> recommendation will be appreciated.

> For this, I have used build directories for each target platform, that  
> also includes the code that change from platform to platform.  
> Then I just cd to that directory and run make.

I think it’s actually a pretty good system, but I would suggest adding  
an additional target (something like ‘buildall’) that creates a  
different sub-directory for each target, and then compiles the target  
in that directory. It’s a fairly small change, and it looks like you  
have everything in place already, but I think that you’ll thank  
yourself later.\> Date: Tue, 14 Aug 2012 16:32:55 -0300

> From: Fabio Panettieri   
> To: SDL Development List   
> Subject: Re: [SDL] Best approach to compile SDL for multiple targets?

---

<div class="post-metadata">

**Author:** ![singmajesty](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/singmajesty/32/2750_2.png) [@singmajesty](https://discourse.libsdl.org/u/singmajesty)\
**Post date:** [August 15, 2012, 7:05pm UTC](https://discourse.libsdl.org/t/best-approach-to-compile-sdl-for-multiple-targets/19060/5 "2012-08-15T19:05:09Z")

</div>

Thanks!

It sounds like integration for Android could be tricky, but we should be able to integrate SDL2 into our “sdl-static” project for each platform build.

Is SDL\_config.h the only file that is modified when you configure the library, or are there other files we would need to save?On Tue, 14 Aug 2012 12:27:37 -0700, Gabriel Jacobo wrote:

> 2012/8/14 Joshua Granick \<@Joshua\_Granick\>
> 
> > Hi!
> > 
> > I am a lead developer for NME, an open-source, cross-platform framework for:
> > 
> > - Windows
> > - Mac
> > - Linux
> > - iOS
> > - Android
> > - BlackBerry
> > - Flash
> > - HTML5
> > 
> > I’ve been thinking of moving to SDL 2.0 for some time. However, the traditional “configure; make; make install” approach seems to work best if you only want the \>\>library on your local machine. I need to be able to compile static versions of SDL for each support native target.
> > 
> > We use our own staging for iOS and Android currently, but I would like to look at what these targets would be like, standardizing on SDL. BlackBerry and webOS \>\>use SDL currently. I probably would like at either continuing to support SDL 1.2 for these targets, or probably helping work on BlackBerry support in SDL 2.0.
> > 
> > Flash and HTML5 probably sound like they come from left-field, but the framework uses Haxe, which can compile to C++, SWF and Javascript, so wild as it is, \>\>they are all related.
> > 
> > My question is which way you recommend to build SDL for all platforms. We have our own make script that helps build all the native dependencies for each target \>\>platform. I am concerned that “configure; make” will result in a binary that is designed for the target machine (like OS X 10.8) rather than a sensible minimum \>\>version, or that trying to configure SDL multiple times for separate targets, in the same directory, will turn out poorly.
> > 
> > Just a few pointers should help, I apologize if this seems like an obvious question. I’m not as involved on the lower level
> > 
> > * * *
> 
> Hi! First of all let me express my admiration for what Haxe and Haxe NME do, I found out about it a few months ago and it really impressed me to the point where I \>almost left my own project to join the Haxe bandwagon. For now, I haven’t jumped ship, but I can give you a few pointers that came out of my experience doing a \>project that has several points of contact with Haxe NME, my Python/Cython based engine Ignifuga ([ignifuga.org](http://ignifuga.org)).
> 
> I compile SDL2 for Windows/Linux/Android/iOS and OS X. Sadly the build system I use is not as uniform as I’d like and it abuses sed in some places (you can see \>the code here: [https://bitbucket.org/gabomdq/ignifuga/src/fc9cbbce5a78/tools/modules/sdl](https://bitbucket.org/gabomdq/ignifuga/src/fc9cbbce5a78/tools/modules/sdl)) but these are a few lessons I learned…
> 
> - With the correct environment variables, you can cross compile and statically link from Linux for Windows (using Mingw) and Linux itself. The only snag I’ve \>encountered is that statically linking libdl produces a segfault when loading Nvidia’s OpenGL stuff dynamically. So, I link to libdl dynamically.
> - Android requires a bit of file rearranging (you have an Android project skeleton that’s included with SDL and you use ndk-build to build it), but I believe it’s possible \>to use the configure;make procedure here as well, if you set the correct environment variables and copy the correct SDL\_config.h file after configuring, but I haven’t \>tried that method. So, under Linux and OS X, I build SDL using ndk-build and the Android project template. The process produces a binary that works on Android \>API Level 5 and up if I recall correctly.
> - For OS X you can build it under OS X (no cross compiling AFAIK), and there’s an included script (build-scripts/fatbuild.sh) which will generate a static fat binary for \>i386, x64 and PPC, with support for OS X 10.6 and higher.
> - For iOS (only cross compiling from OS X), based on my work for Ignifuga I recently added a iosbuild.sh script which will do what fatbuild.sh does but for iOS use. It \>will generate a static binary for armv6, armv7 and i386 (for simulator use)
> - Both fatbuild.sh and iosbuild.sh show examples of how to configure for multiple targets using the same code base and different build directories.
> 
> –Gabriel.

---

<div class="post-metadata">

**Author:** ![Gabriel\_Jacobo](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/gabriel_jacobo/32/1968_2.png) [@Gabriel\_Jacobo](https://discourse.libsdl.org/u/Gabriel_Jacobo)\
**Post date:** [August 16, 2012, 4:16pm UTC](https://discourse.libsdl.org/t/best-approach-to-compile-sdl-for-multiple-targets/19060/6 "2012-08-16T16:16:19Z")

</div>

2012/8/15 Joshua Granick

> \*\*  
> Thanks!
> 
> It sounds like integration for Android could be tricky, but we should be  
> able to integrate SDL2 into our “sdl-static” project for each platform  
> build.
> 
> Is SDL\_config.h the only file that is modified when you configure the  
> library, or are there other files we would need to save?

I think so, SDL\_config.h and the Makefile. For Android, you’ve got to use  
the SDL\_config\_android.h and overwrite it on top of SDL\_config.h. The same  
thing for iOS if you want to build from the command line as the configure  
script will not make a valid SDL\_config.h  
One additional detail, for newer versions of the NDK (\>=r8b) you may need  
to run “android update project” on the Android skeleton that ships with SDL  
as it is prepared for earlier versions of the NDK and if IIRC there were a  
few gotchas involved when using the newest NDK.–  
Gabriel.
