Devilutionx: Static binary

Created on 22 May 2019  路  14Comments  路  Source: diasurgical/devilutionX

Hello,
could you tell me how to build a static devilutionx binary?
I tried to launch devilutionx32 bits on a fresh Ubuntu 64 bits and each time I installed a 32 bits library it asked for another, I gave up after the 10th library.

question

All 14 comments

I'm not really sure what issue you are having, if you can build it you should have all the needed libraries to run it. Setting the build to release mode will statically link all but libc and sdl.
cmake -DBINARY_RELEASE=ON ..

the aim of this question is to build a binary, 32 or 64 bits, that will not need to install dependencies. The Linux devilutionx 32 bits release available on your github needs a lot of 32 bits libraries.

It's still not clear what you are referring to, as you can see here we have statically linked everything except SDL and libc:

objdump -p devilutionx | grep NEEDED
  NEEDED               libSDL2_ttf-2.0.so.0
  NEEDED               libSDL2_mixer-2.0.so.0
  NEEDED               libSDL2-2.0.so.0
  NEEDED               libm.so.6
  NEEDED               libpthread.so.0
  NEEDED               libc.so.6
  NEEDED               ld-linux.so.2

You can't statically link libc as it will conflict with the installed version, and you shoudn't statically link SDL as it's the system abstraction so a version befitting the system should be used instead of what you might have had available on the build system.

In case it's not clear libm, libpthread are part of libc, ld-linux is used to load liberies.

If you are having issues with other dependencies I will need you to be more specific then "a lot of 32 bits libraries". Maybe you are trying to run it on a 64bit system with out multi arch installed? Trying to avoiding that would be the same as trying to include the entire GNU/Linux distribution in the application. You can think of it as trying to statically linking Wine to avoid a dependency on Windows, it the result would be huge and probably only run on systems that are piratically identical to the build system.

On 64 bit Ubuntu all you need to install is:
sudo apt install libsdl2-mixer-2.0-0:i386 libsdl2-ttf-2.0-0:i386
The package manager will take care of any system specific dependencies that you might have.

Ok, thank you for this complete answer.

I guess what you are looking for is the 64bit builds, I expect 2/5 of the remaining issues will be solved later today.

What about building the dependencies like libsdl into the executable so no libraries are needed at all to be installed?

See my previous post for why that is not a good idea: https://github.com/diasurgical/devilutionX/issues/117#issuecomment-495196637

Also, that still wouldn't solve the issue here, running 32bit on a 64bit system without first installing support for 32bit programs.

Hello again,
actually if I compile a 64 bit DevilutionX build and check the binary dependencies, I obtain this list:

$ objdump -p devilutionx | grep NEEDED
  NEEDED               libasan.so.5
  NEEDED               libSDL2_ttf-2.0.so.0
  NEEDED               libSDL2_mixer-2.0.so.0
  NEEDED               libSDL2-2.0.so.0
  NEEDED               libstdc++.so.6
  NEEDED               libm.so.6
  NEEDED               libgcc_s.so.1
  NEEDED               libpthread.so.0
  NEEDED               libc.so.6

Can I do better? (less dependencies?)
My config: Ubuntu 19.04 64 bits

Did you try with -DBINARY_RELEASE=ON on?

nope, could you tell me what will be the benefit of this option?

It will statically link most things and avoid some debugs.

You can read about it here:
https://github.com/diasurgical/devilutionX#general

I will give it a try, thanks.

Thank you @OrangBuangan, this option reduced exe size by 5: 20 Mo --> 4 Mo.

compile options:
ASAN ON
BINARY_RELEASE ON
CMAKE_BUILD_TYPE Release
CMAKE_INSTALL_PREFIX /usr/local
DEBUG ON
DIST OFF
FASTER ON
NIGHTLY_BUILD OFF
SDL2_DIR /usr/lib/x86_64-linux-gnu/cmake/SDL2
pkgcfg_lib_SDL2PC_SDL2 /usr/lib/x86_64-linux-gnu/libSDL2.so
pkgcfg_lib_SDL2_mixerPC_SDL2 /usr/lib/x86_64-linux-gnu/libSDL2.so
pkgcfg_lib_SDL2_mixerPC_SDL2_m /usr/lib/x86_64-linux-gnu/libSDL2_mixer.so
pkgcfg_lib_SDL2_ttfPC_SDL2 /usr/lib/x86_64-linux-gnu/libSDL2.so
pkgcfg_lib_SDL2_ttfPC_SDL2_ttf /usr/lib/x86_64-linux-gnu/libSDL2_ttf.so
pkgcfg_lib_sodium_PKG_sodium /usr/lib/x86_64-linux-gnu/libsodium.so
sodium_USE_STATIC_LIBS ON

dependencies:
objdump -p devilutionx | grep NEEDED
NEEDED libSDL2_ttf-2.0.so.0
NEEDED libSDL2_mixer-2.0.so.0
NEEDED libSDL2-2.0.so.0
NEEDED libm.so.6
NEEDED libpthread.so.0
NEEDED libc.so.6
NEEDED ld-linux-x86-64.so.2

You should probably also change:
ASAN OFF
DEBUG OFF
DIST ON
FASTER OFF

You can also use strip -s devilution to reduce the size further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cosmincrihan picture cosmincrihan  路  3Comments

AJenbo picture AJenbo  路  5Comments

namtsui picture namtsui  路  3Comments

kraileth picture kraileth  路  4Comments

matthewrkarlsen picture matthewrkarlsen  路  3Comments