Page 1 of 1
How to compile a Windows/MingW static gcc IM [solved/howto]
Posted: 2014-07-31T02:41:56-07:00
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.
Re: How to compile a Windows/MingW static IM?
Posted: 2014-07-31T04:51:24-07:00
by magick
Try 'configure --enable-static --disable-shared'. Now build. Does that work for you?
Re: How to compile a Windows/MingW static IM?
Posted: 2014-07-31T05:27:06-07:00
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
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.
Re: How to compile a Windows/MingW static IM [solved/howto]
Posted: 2014-07-31T11:27:00-07:00
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.