Does anyone static link SDL2?

I use Ubuntu OS. I am trying to static link my program (called graf.cpp) with the libraries required for SDL2. I have the sdl2-config file from a fresh SDL2 build.
When I run command line: sdl2-config --libs it tells me the libraries to link are: -L/usr/lib/x86_64-linux-gnu -lSDL2. -L/usr/lib/x86_64-linux-gnu references all of the libraries at that path, and -lSDL2 references SDL2 dynamic object specifically. Since i need to static link the libraries I run the following command line:
g++ graf.cpp -o graf --static -L/usr/lib/x86_64-linux-gnu -lSDL2. I am pretty sure this is the correct way to do it. When I do it, g++ generates hundreds of errors for undefined references and the build fails. I get a similar result when I link with only the flag -lSDL2. NOTE: I get similar result linking to all the *.a static library files for SDL2.

The problem is that the linked libraries contain references to things in other libraries not being linked. I need to link additional libraries. One indication of the missing libraries can be gotten running:
ldd /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0 which shows 41 other libraries the that the dynamic library is dependent on. I assume the static libraries similarly require additional libraries. But these are unknown.

MY QUESTION is: has anyone here done static linking of SDL2 libraries? If so, please tell me how to do it

There should be a --static-libs option for sdl2-config, containing the
required libraries.On May 14, 2015 7:55 AM, “bilsch01” wrote:

I use Ubuntu OS. I am trying to static link my program (called graf.cpp)
with the libraries required for SDL2. I have the sdl2-config file from a
fresh SDL2 build.
When I run command line: sdl2-config --libs it tells me the libraries to
link are: -L/usr/lib/x86_64-linux-gnu -lSDL2. -L/usr/lib/x86_64-linux-gnu
references all of the libraries at that path, and -lSDL2 references SDL2
dynamic object specifically. Since i need to static link the libraries I
run the following command line:
g++ graf.cpp -o graf --static -L/usr/lib/x86_64-linux-gnu -lSDL2. I am
pretty sure this is the correct way to do it. When I do it, g++ generates
hundreds of errors for undefined references and the build fails. I get a
similar result when I link with only the flag -lSDL2. NOTE: I get similar
result linking to all the *.a static library files for SDL2.

The problem is that the linked libraries contain references to things in
other libraries not being linked. I need to link additional libraries. One
indication of the missing libraries can be gotten running:
ldd /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0.2.0 which shows 41 other
libraries the that the dynamic library is dependent on. I assume the static
libraries similarly require additional libraries. But these are unknown.

MY QUESTION is: has anyone here done static linking of SDL2 libraries? If
so, please tell me how to do it


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Right. I tried that also (weeks ago). Using --static-libs with sdl2-config gives more linker flags but the following two error messages occur when using those flags:

warning: Using ‘dlopen’ in statically linked applications requires at runtime the shared libraries from the glibc version used for linking.
/usr/bin/ld: cannot find -lts

I tried linking without flag -lts. It compiles but the resulting program hangs up. Which brings me back to my question: has anybody ever static linked with SDL2 ? If so, please tell me how.

Thanks. Bill S.

I’m static linking on OS X but that needed some tweaking of sdl2-config https://forums.libsdl.org/viewtopic.php?t=10956&highlight=

FWIW, I only managed to link statically by passing -static to the (that’s
one dash! I think…) to the linker. If I just passed it as a regular
option it wouldn’t work. I also didn’t manage to only static link sdl, and
everything else dynamically. For me it’s either static everything or
dynamic everything. Not sure why I couldn’t get it to work but I suspect my
lack of expertise.On 14 May 2015 at 12:33, bilsch01 wrote:

Right. I tried that also (weeks ago). Using --static-libs with
sdl2-config gives more linker flags but the following two error messages
occur when using those flags:

warning: Using ‘dlopen’ in statically linked applications requires at
runtime the shared libraries from the glibc version used for linking.
/usr/bin/ld: cannot find -lts

I tried linking without flag -lts. It compiles but the resulting program
hangs up. Which brings me back to my question: has anybody ever static
linked with SDL2 ? If so, please tell me how.

Thanks. Bill S.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org