Static Linking

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
picasso
Posts: 8
Joined: 2011-09-03T22:58:32-07:00
Authentication code: 8675308

Static Linking

Post by picasso »

Hi All,
I need some help about static linking of ImageMagick. As I get by reading some threads, building ImageMagick statically ( ./configure --disable-shared
) isn't enough, anybody can explain it, please?
Thanks
picasso
Posts: 8
Joined: 2011-09-03T22:58:32-07:00
Authentication code: 8675308

Re: Static Linking

Post by picasso »

Why nobody helps?
Compile configuration command that I use:
./configure --disable-shared --disable-dependency-tracking --without-threads --enable-delegate-build LDFLAGS="-static" --prefix=/usr

and the result :
-------------------------------------------------------------------------------
Shared libraries --enable-shared=yes yes
Static libraries --enable-static=yes yes
Module support --with-modules=no no
GNU ld --with-gnu-ld=yes yes
Quantum depth --with-quantum-depth=16 16
High Dynamic Range Imagery
--enable-hdri=no no

Delegate Configuration:
BZLIB --with-bzlib=yes yes
Autotrace --with-autotrace=no no
Dejavu fonts --with-dejavu-font-dir=default none
DJVU --with-djvu=yes no
DPS --with-dps=yes no
FFTW --with-fftw=yes no
FlashPIX --with-fpx=yes no
FontConfig --with-fontconfig=no no
FreeType --with-freetype=yes yes
GhostPCL None pcl6 (unknown)
GhostXPS None gxps (unknown)
Ghostscript None gs (9.02)
Ghostscript fonts --with-gs-font-dir=default /usr/share/ghostscript/fonts/
Ghostscript lib --with-gslib=no no
Graphviz --with-gvc=yes no
JBIG --with-jbig=yes no
JPEG v1 --with-jpeg=yes yes
JPEG-2000 --with-jp2=yes no
LCMS v1 --with-lcms=yes no
LCMS v2 --with-lcms2=yes no
LQR --with-lqr=yes no
LZMA --with-lzma=yes no
Magick++ --with-magick-plus-plus=yes yes
OpenEXR --with-openexr=yes no
PERL --with-perl=no no
PNG --with-png=yes yes
RSVG --with-rsvg=no no
TIFF --with-tiff=yes yes
WEBP --with-webp=yes no
Windows fonts --with-windows-font-dir= none
WMF --with-wmf=yes no
X11 --with-x= no
XML --with-xml=no no
ZLIB --with-zlib=yes yes
Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

Re: Static Linking

Post by Jason S »

I assume that what you want is for the ImageMagick utilities like convert and identify to be static executables. I don't know any way to do that, that isn't a hack.

After you run configure, try editing Makefile, and appending "-all-static" to the line that starts with "LDFLAGS =". That will cause libtool to link everything statically.

However, because configure didn't know you were going to link statically, it may not have correctly figured out which third-party libraries are available. You may have disable some libraries, and/or do some hacking, to make everything work.
picasso
Posts: 8
Joined: 2011-09-03T22:58:32-07:00
Authentication code: 8675308

Re: Static Linking

Post by picasso »

Yes, that's what we need. I have to redistribute the convert tool in LFS ( Linux from Scratch ).
First of all I install staticly delegates ( tiff, jpeg, png, zlib, ... ) >>> ./configure --disable-share --enable-static
then I try to install image magick but I can't build a static convert and so on.
picasso
Posts: 8
Joined: 2011-09-03T22:58:32-07:00
Authentication code: 8675308

Re: Static Linking

Post by picasso »

I get an error when trying LDFLAGS="-all-static"

configuring ImageMagick 6.7.2-1
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking whether build environment is sane... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/root/magick/ImageMagick-6.7.2-1':
configure: error: C compiler cannot create executables
See `config.log' for more details
picasso
Posts: 8
Joined: 2011-09-03T22:58:32-07:00
Authentication code: 8675308

Re: Static Linking

Post by picasso »

Jason S wrote:I assume that what you want is for the ImageMagick utilities like convert and identify to be static executables. I don't know any way to do that, that isn't a hack.

After you run configure, try editing Makefile, and appending "-all-static" to the line that starts with "LDFLAGS =". That will cause libtool to link everything statically.

However, because configure didn't know you were going to link statically, it may not have correctly figured out which third-party libraries are available. You may have disable some libraries, and/or do some hacking, to make everything work.
Thank you very much jason! that was a great help, and finally I build a static "convert" tool! :D
kaputzke
Posts: 3
Joined: 2011-09-19T07:09:50-07:00
Authentication code: 8675308

Re: Static Linking

Post by kaputzke »

Hi picasso, could you post your ./configure line after which you modified Makefile with -all-static?
picasso
Posts: 8
Joined: 2011-09-03T22:58:32-07:00
Authentication code: 8675308

Re: Static Linking

Post by picasso »

my config command :

./configure --enable-shared=no --enable-static=yes --enable-delegate-build=yes --with-modules=no --prefix=/usr --without-threads

############

Now I want make a static convert with ghostscript !!! but it's really hard to do
after adding this --with-gslib=/usr/lib to ./configure ... , when run ( make LDFLAGS="-all-static" ) I get this error :

magick/.libs/libMagickCore.a(magick_libMagickCore_la-utility.o): In function `ExpandFilename':
magick/utility.c:648: warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: cannot find -lgs
collect2: ld returned 1 exit status
make[1]: *** [utilities/animate] Error 1
make[1]: Leaving directory `/root/magick/ImageMagick-6.7.2-1'
make: *** [all] Error 2

this is from config result :

LIBS = -lMagickCore -ltiff -ljpeg -lgs -lpng12 -lbz2 -lz -lm
CXX = g++
CXXFLAGS = -g -O2

any idea?
kaputzke
Posts: 3
Joined: 2011-09-19T07:09:50-07:00
Authentication code: 8675308

Re: Static Linking

Post by kaputzke »

Thank you for the config option, for me it fails at the same location for another lib:

/usr/bin/ld: cannot find -ltiff
collect2: ld returned 1 exit status
make[1]: *** [utilities/animate] Error 1
make[1]: Leaving directory `/home/tkrawuts/tmp/immck/ImageMagick-6.7.2-7'
make: *** [all] Error 2

The ouput of "make V=1":

make all-am
make[1]: Entering directory `/home/tkrawuts/tmp/immck/ImageMagick-6.7.2-7'
/bin/sh ./libtool --tag=CC --mode=link gcc -std=gnu99 -std=gnu99 -g -O2 -Wall -L/home/tkrawuts/tmp/immck/ImageMagick-6.7.2-7/magick -L/home/tkrawuts/tmp/immck/ImageMagick-6.7.2-7/wand -all-static -L/home/tkrawuts/tmp/immck/ImageMagick-6.7.2-7/magick -L/home/tkrawuts/tmp/immck/ImageMagick-6.7.2-7/wand -all-static -o utilities/animate utilities/animate.o magick/libMagickCore.la wand/libMagickWand.la
libtool: link: gcc -std=gnu99 -std=gnu99 -g -O2 -Wall -static -static -o utilities/animate utilities/animate.o -L/home/tkrawuts/tmp/immck/ImageMagick-6.7.2-7/magick -L/home/tkrawuts/tmp/immck/ImageMagick-6.7.2-7/wand magick/.libs/libMagickCore.a wand/.libs/libMagickWand.a /home/tkrawuts/tmp/immck/ImageMagick-6.7.2-7/magick/.libs/libMagickCore.a -ltiff -lfreetype -ljpeg -lpng12 -lfontconfig -lXext -lXt -lz -lSM -lICE -lX11 -lgomp -lm
/usr/bin/ld: cannot find -ltiff

You can see the -all-static switch.
I am missing /usr/lib/libtiff.a for static linking, only .so are there. Just for a test I added --without-tiff to verify it fails at the next lib:

CCLD utilities/animate
/usr/bin/ld: cannot find -lfreetype
collect2: ld returned 1 exit status

So I assume I need some static libraries for tiff etc and you for gs. Or do you have libgs.a?
Which raises the question how to get/compile these libraries? The .a libs are noct part of -devel packages

Anyway I found a precompiled static 6.5.9 binary here which works fine for my application (its ok to create pdf):
http://lists.typo3.org/pipermail/typo3- ... 65202.html
Jason S
Posts: 103
Joined: 2010-12-14T19:42:12-07:00
Authentication code: 8675308

Re: Static Linking

Post by Jason S »

Of course, you need a static version (.a file) of any library that you're going to statically link to. If you can't get a static libtiff (etc.) from the same source as your shared libtiff, you'll have to build one yourself. That's usually not very hard, but you may need to be careful about how you configure it, and about possible version mismatches.

I don't really understand ImageMagick's relationship with GhostScript. Someone else will have to answer that. But if you do link ImageMagick and GhostScript, note that you might not be allowed to distribute the combined product. You'd be violating GhostScript's license, unless you can legitimately relicense everything to GPLv3.
picasso
Posts: 8
Joined: 2011-09-03T22:58:32-07:00
Authentication code: 8675308

Re: Static Linking

Post by picasso »

kaputzke wrote: /usr/bin/ld: cannot find -ltiff
collect2: ld returned 1 exit status
make[1]: *** [utilities/animate] Error 1
make[1]: Leaving directory `/home/tkrawuts/tmp/immck/ImageMagick-6.7.2-7'
make: *** [all] Error 2
before installing imagemagick you must compile delegates statically, try this for tiff, jpeg, zlib and so on :
./configure --enable-shared=no --enable-static=yes --prefix=/usr
then compile IM :
./configure --enable-shared=no --enable-static=yes --enable-delegate-build=yes --with-modules=no --without-threads --prefix=/usr
make LDFLAGS="-all-static"
make install
kaputzke wrote: So I assume I need some static libraries for tiff etc and you for gs. Or do you have libgs.a?
yes, that's true! but I don't know how make libgs.a !
kaputzke
Posts: 3
Joined: 2011-09-19T07:09:50-07:00
Authentication code: 8675308

Re: Static Linking

Post by kaputzke »

yes that worked,- so now I am stuck at the same point,- no libgs.a... I tried several versions and variants (ghostscript, gnu-ghostscript, espgs) but none of the buildchains spit out an libgs.a. A simple "ar -rv libgs.a objs/*o" in ghostscript build dir produced a non working library.
picasso
Posts: 8
Joined: 2011-09-03T22:58:32-07:00
Authentication code: 8675308

Re: Static Linking

Post by picasso »

After a period of a couple months, I came-back to this project again! I'm going to find a solution for this problem
Any ideas?
Can somebody explain the relation between gs and imagemagick?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Static Linking

Post by fmw42 »

Imagemagick uses Ghostscript as a delegate library to handle some vector format images, such as pdf.

If convert -list configure does not show gs in the line starting with DELEGATES, then IM has not found GS when IM was installed.
Post Reply