Build static binary

Bug #548959 reported by Jens Beyer
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
widelands
Won't Fix
Wishlist
Unassigned

Bug Description

We should try to convince CMake to build a binary as statically as possible.

Nasenbaer (nasenbaer)
Changed in widelands:
status: New → Confirmed
Revision history for this message
SirVer (sirver) wrote :

This could benefit us on OS X as well. Note that SDL-Mixer loads some libs dynamically at runtime, to build a prober static lib, libsdl-mixer must be compiled statically as well:

--disable-music-mp3-shared
--disable-music-ogg-shared
--disable-music-flac-shared

These tipps came from David Allwicher.

Revision history for this message
Timowi (timo-wingender) wrote :

@SirVer:
This has nothing to do with widelands and is only a part which is necessary. Some libraries load plugins or other libraries at runtime. This just depends on your library setup. There are more necessary/recommendable options to get a nice environment for static linking.

I would not try to do a complete static linking with cmake. The linking itself is quite easy. But it can take much time to set up the library environment. I work on a script (or Makefile) which set up these libraries for widelands. For 64bit this was not a big problem as I have 32bit libraries from system only and compiled all 64bit ones myself. For 32bit this was more difficult as the compiled libraries conflicts with the system ones.

It would be helpful for static linking if it is possible to set more options. First of all is should be possible to throw out all default path. It should not use /usr/include at all but include some special path /path/to/static-libs/include the same with the libraries.

Then I want to call cmake somethin like this:

cmake -DTAKE_ONLY_MY_INCLUDES="-I... -I..." -DSDL_LIBRARIES="/usr/static32/lib/libSDL.a /usr/static32/lib/libSDL_gfx.a /usr/static32/lib/libfreetype.a" -DGGZ_LIBRARIES="/usr/static32/lib/libggzmod.a /usr/static32/lib/libggz.a /usr/static32/lib/libexpat.a" -DCOMMON_LIBS="-static -nodefaultlibs -lz -ldl -lm -lgcc_eh -lgcc"

This would make the process much easier. Options for static linking will just be to much system dependent. I will write a bit about how to link widelands static. Most of this will be about how to compile the libraries for it.

Revision history for this message
Jari Hautio (jarih) wrote :

Timo, you can use -DCMAKE_PREFIX_PATH="/usr/static32" to get cmake to search includes and libs first from preferred statically linked dir. If you just want to point libs there, use CMAKE_LIBRARY_PATH. If a library is not statically, linked cmake continues to search from system paths.

Revision history for this message
Timowi (timo-wingender) wrote :

@Jari

I know there is something like this. But is is not enough. I want to specify the options manually. It should not search system libraries at all. I currently do it manual. Would just nice to give everything just to cmake and use make to build the executable.

Revision history for this message
Timowi (timo-wingender) wrote :

In revision 5463 I changed the order libraries are linked in. Now it is possible to build a static binary with cmake with minor glitches. Just some dependent libraries are missing. In src/CMakeLists.txt line 139ff are tests for WIN32 to compile in missing libraries. But these libraries are necessary on other platforms too. It is better to try linking test programs to see if they are needed.

common dependencies to test are:

Test if glibc contains gettext or if we need to link against libintl
libggz: expat grcypt gpg-error ws2_32
SDL_image: jpeg tiff png libz
SDL_mixer: vorbisfile vorbis ogg winmm(WIN32) asound(Linux)
SDL_ttf: freetype

currently libjpeg and libtiff are linked unconditionally but are not used by widelands. These should only linked in if SDL_image needs them.

Revision history for this message
Jari Hautio (jarih) wrote :

Windows/MSVC build is setup to use statically linked libraries. To keep changes minimal in widelands side, I linked most of the dependent libraries straight in the SDL_image, SDL_mixer and SDL_ttf. Still it propably is better to link everything explicitly from widelands. I'll be happy to update MSVC libraries to support individual libraries when static linking is ready.

In addition to Timo's list libintl had dependency to iconv library, which had to be separately linked from widelands. Msvc version of ggz excludes gcrypt support and does not need gcrypt or gpg-error.

Then there's issue of acknowledgements related to third party libraries that are linked to widelands. For example jpeg library, requires specific phrase: "this software is based in part on the work of the Independent JPEG Group" in the distributed documentation. Perhaps CREDITS file should contain acknowlodegements for all dependent libraries.

Revision history for this message
Jens Beyer (qcumber-some) wrote :

Proposed solution is to add a possibility to specify a set of libraries which are used at the end of the linking command line.

Revision history for this message
SirVer (sirver) wrote :

What is the status of this? It seems it is more a feature request than a bug report. Maybe it is already implemented?

I target this for build 17 now; if this is indeed a proper bug, please speak up now.

Changed in widelands:
milestone: build16-rc1 → build17-rc1
Revision history for this message
SirVer (sirver) wrote :

okay, noone seems to care for this bug anymore. At least my last comment went unanswered. I distarget this and set to invalid. I will close when it resurfaces.

Changed in widelands:
status: Confirmed → Incomplete
milestone: build17-rc1 → none
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for widelands because there has been no activity for 60 days.]

Changed in widelands:
status: Incomplete → Expired
SirVer (sirver)
Changed in widelands:
status: Expired → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.