How to compile a Windows/MingW static gcc IM [solved/howto]

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
User avatar
Marsu42
Posts: 75
Joined: 2014-06-12T03:17:45-07:00
Authentication code: 6789
Location: Berlin

How to compile a Windows/MingW static gcc IM [solved/howto]

Post by Marsu42 »

The download page http://www.imagemagick.org/script/binar ... hp#windows offers an all-static version of IM with all dependencies packed into one exe.

Problem: I'm failing to reproduce this compilation, with LDFLAGS=-static just the IM dependencies are included but the exes are still looking for the other dependencies (like libtiff-5.dll and so on) as separate files. The flag "-all-static" as suggested in older posts doesn't work on newer gcc versions. I'm using cygwin64 targeting x86_64-w64-mingw32 with gcc 4.8.3.

Request:: Could you please share the LDFLAGS or detailed compilation steps to produce single windows static exe files?

Thanks!

Edit: See solution below.
Last edited by Marsu42 on 2014-07-31T11:41:08-07:00, edited 2 times in total.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How to compile a Windows/MingW static IM?

Post by magick »

Try 'configure --enable-static --disable-shared'. Now build. Does that work for you?
User avatar
Marsu42
Posts: 75
Joined: 2014-06-12T03:17:45-07:00
Authentication code: 6789
Location: Berlin

Re: How to compile a Windows/MingW static IM?

Post by Marsu42 »

magick wrote:Try 'configure --enable-static --disable-shared'. Now build. Does that work for you?
Nope, already did that, sorry for not mentioning it :-o

My current research indicates that "problem" is that the dependencies like libtiff are already there by the cygwin package manager system in static and shared versions, and gcc-ld takes the shared one with no way to change the preference order. I'm currently trying to force ld to use the static version by explicitly stating -l:libtiff.a and so on which is a pita to figure out. I'll report back once this idea works or fails, probably I'm not the only one trying to build im as static with gcc.
User avatar
Marsu42
Posts: 75
Joined: 2014-06-12T03:17:45-07:00
Authentication code: 6789
Location: Berlin

Re: How to compile a Windows/MingW static IM [solved/howto]

Post by Marsu42 »

Ok, I've got the solution and post it here for reference. As already assumed, gcc-ld defaults to shared libs if they exist no matter what you tell it, LDFLAGS='-static' or not. The "proper" though intricate solution seems to be to explicitly link all required libs with LDFLAGS='-static -static-libgcc -static-libstdc++ -l:lib1.a -l:lib2.a' and so on.

The tricky part is to know what libs are required. What I did is to compile a shared version and then run dependency walker on an exe so I know what dll dependency tree is loaded. With this information you can then look for the static mingw .a lib names wherever your packet manager has put them.

With this method and the configure switches '--enable-static --disable-shared --disable-installed --disable-modules --disable-delegate-build --enable-zero-configuration' (I don't know if all are really necessary) you end up with a single, self-contained gcc compiled exe that you can put anywhere you like.
Post Reply