17

I have been trying to produce a statically linked "single binary" version of my game for windows. I want to link with sdl, sdl_image and sdl_mixer which in turn pull in a few support libraries. Unfortunately I haven't found a way to get them all to compile and link using cygwin/mingw/gcc. As far as I can tell all existing public versions are only shared libraries / dlls.

Please note that I'm not talking about licencing here. The source will be open thus the GPL/LGPLness of sdl is not relevant.

prakash
  • 58,901
  • 25
  • 93
  • 115
Sec
  • 7,059
  • 6
  • 31
  • 58
  • I didn't want to be the accepted answer for incompleteness :(. If you can provide more information (like the output from the sdl-config calls, and a list of the linker errors), I'm willing to try to fix my answer. – Alex Lyman Feb 11 '09 at 16:12
  • sdl --static-libs returns: "-L/usr/local/lib -lmingw32 -lSDLmain -lSDL -mno-cygwin -mwindows" which looks correct to me. Any other info I can give you? – Sec Feb 22 '09 at 18:23

5 Answers5

22

When compiling your project, you need to make just a couple changes to your makefile.

  • Instead of sdl-config --libs, use sdl-config --static-libs
  • Surround the use of the above-mentioned sdl-config --static-libs with -Wl,-Bstatic and -Wl,-Bdynamic. This tells GCC to force static linking, but only for the libraries specified between them.

If your makefile currently looks like:

SDLLIBS=`sdl-config --libs`

Change it to:

SDLLIBS=-Wl,-Bstatic `sdl-config --static-libs` -Wl,-Bdynamic

These are actually the same things you should do on Unix-like systems, but it usually doesn't cause as many errors on Unix-likes if you use the simpler -static flag to GCC, like it does on Windows.

Alex Lyman
  • 15,637
  • 3
  • 38
  • 42
  • I'm marking this as the answer because it seems like the best Answer. Yet I still can't get it to work as I'm getting loads of "undefined reference" to functions like _waveOutOpen@24 or _timeGetTime@0. – Sec Feb 10 '09 at 12:54
  • @Sec those are requirements pulled in because the SDL static library uses them. The WInMM multi-media library and a few others will likely have to be added to your link line. – WhozCraig Mar 07 '15 at 13:26
2

Via this SDL mailing list post it seems that the sdl development tools ship with a sdl-config script that you can use with the --static-libs flag to determine what linker flags you need to use.

David Locke
  • 17,926
  • 9
  • 33
  • 53
1

Environment: VMWare Virtual Machine with Windows 7 x64 and Equipment we Dev c + + build 7.4.2.569, complilador g+ + (tdm-1) 4.6.1

Once, SDL2-2.0.3 API installed as configuration Dev c ++ is not very clear what I've done as tradition requires command line.

The first problem is that Windows 7 appears to have changed the methodology and they go to his ball. Inventory. Ref. https://stackoverflow.com/users/464581/cheers-and-hth-alf

After the first hurdle, SDL_platform.h is that bad, it's down another, I do not remember where I downloaded, but the next does not work in the indicated version.

We must put SDL2.h ls in the directory of the executable.

D:\prg_desa\zsdl2>g++ bar.cpp main.cpp -o pepe1 -ID:\SDL2-2.0.3\i686-w64-mingw32\include\SDL2 -LD:\SDL2-2.0.3\i686-w64-mingw32\lib -lmingw32 -lSDL2main -lSDL2 -mwindow

I've finally compiled and works SDL2 testing.

Community
  • 1
  • 1
Anónimo
  • 11
  • 1
  • Here you have the sources: bar.cpp #undef UNICODE, #define UNICODE, #include , #include ,include ,Using namespace std; ,int wmain(int argc,wchar_t* argv[] ),{ wostringstream text; text< – Anónimo May 10 '14 at 20:09
  • main.cpp # include#include#include # include using namespace std; int main(int argc,char *argv[]) {SDL_Surface *screen;SDL_Event event; if(SDL_Init( SDL_INIT_VIDEO)==-1) {SDL_GetError());return 1;} MessageBox(0, TEXT( "Pulsa el OK"),TEXT("Hola"), MB_SETFOREGROUND); while( SDL_WaitEvent event)){if(event.type==SDL_QUIT) break; } SDL_Quit ( );return 0;} – Anónimo May 10 '14 at 20:17
0

That's because the SDL libs are under the LGPL-license.

If you want to static link the libs (you can do that if your recompile them. It needs some hacking into the makefiles though) you have to place your game under some compatible open source license as well.

The SDL-libs come as shared libraries because most programs that use them are closed source. The binary distribution comes in a form that most people need.

Nils Pipenbrinck
  • 83,631
  • 31
  • 151
  • 221
  • 1
    LGPL is a very permissive license and does allow static inclusion in closed source apps. It's the GPL that doesn't allow inclusion in closed source apps except with the dll type inclusion. – KPexEA Sep 22 '08 at 16:26
  • afaik GPL does not allow any kind of linking with closed source. LGPL allows dynamic linking (Users must be able to update/change the LGPL-code). Static linking with LGPL in a closed source software is a no-no. – Nils Pipenbrinck Sep 22 '08 at 16:45
  • 3
    As long as you provide customers with the facility to re-link to LGPL libraries if they wish, you can provide statically linked binaries. You must also include the LGPL and state that the library used falls under this licence. – Artelius Feb 06 '09 at 00:03
0

On my system (Ubuntu) I have to use the following flags:

-Wl,Bstatic -lSDL_image `sdl-config --libs` -lpng12 -lz -ltiff -ljpeg -lasound -laudio -lesd -Wl,-Bdynamic `directfb-config --libs` -lpulse-simple -lcaca -laa -ldl

That links SDL, SDL_image, and many of their dependencies as static. libdl you never want static, so making a fully-static binary that uses SDL_image is a poor idea. pulse,caca,aa, and directfb can probably be made static. I haven't got far enough to figure them out yet.

singpolyma
  • 10,999
  • 5
  • 47
  • 71