2

Let's take this snippet:

#include "SDL/SDL.h" 
int main( int argc, char* args[] ) 
{ 
    SDL_Init( SDL_INIT_EVERYTHING ); 
    SDL_Quit();
    return 0; 
}

Compile command would be:

g++ -o myprogram mysource.cpp -lSDL

How can I 'include' SDL in my executable so that another enduser can execute it at once (without installing SDL or even recompiling my source) ?

user1511417
  • 1,880
  • 3
  • 20
  • 41
  • `g++ -o myprogram -static mysource.cpp -lSDL` would be a way to do this, however that statically links everything, thus also libc. – DipSwitch Jul 11 '12 at 14:59
  • This doesn't work for me, i get literally thousands of errors and undefined references to things within SDL that it can't find. LITERALLY THOUSANDS. E.g: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libSDL2_image.a(IMG_png.o): In function `IMG_InitPNG': (.text+0x3ab1): undefined reference to `png_create_info_struct' – Owl Feb 21 '19 at 16:02

1 Answers1

1

Try:

g++ -o myprogram mysource.cpp -Wl,-Bstatic \
    $(sdl-config --static-libs) -Wl,-Bdynamic
betabandido
  • 18,946
  • 11
  • 62
  • 76
slartibartfast
  • 4,348
  • 5
  • 31
  • 46
  • The binary is too small to have statically linked in SDL. This isn't the correct solution. – Owl Feb 21 '19 at 16:01
  • `ldd path/to/output/binary` is a sure way to check if the resulting binary requires any specifc libraries. No need to guess based on file size. – Mikko Rantalainen Oct 24 '22 at 21:15