Hi All,
I am new to ImageMagik, and I want to link it statically to my C Code.
Detector: Detector.cpp TDCommon.cpp ./SVMLight_Classifier/svm_common.c
g++-4.1 Detector.cpp TDCommon.cpp ./SVMLight_Classifier/svm_common.c `Magick++-config --cppflags --cxxflags --ldflags --libs` -o "Detector" -I "./SVMLight_Classifier/"
This is the part of my make file, which I use to compile. It all works fine when there is the same version of ImageMagik, otherwise it wont work.
This code is not statically compiled, and if some could let me know what modifications that I need to do to make a static linking, It will be great
Thanks!
Vikram
Static Linking of ImageMagik
Re: Static Linking of ImageMagik
The default ImageMagick build is usually dynamic. To build a static version of ImageMagick download the source and type:
- cd ImageMagick-6.4.4
./configure --disable-shared
make
make install
Re: Static Linking of ImageMagik
It is never too late to say a thanks.
In order to be very sure that the program is statically compiled, I used --static switch.
g++ Transform.cpp --static `Magick++-config --cppflags --cxxflags --ldflags --libs` -o "Transform"
This was the result:
Transform.cpp:11:2: warning: no newline at end of file
/usr/lib/libjasper.a(jas_stream.lo): In function `jas_stream_tmpfile':
(.text+0x376): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
/usr/lib/libMagick.a(magick_libMagick_la-delegate.o): In function `AcquireTemporarySymlink':
(.text+0x2b5): warning: the use of `tempnam' is dangerous, better use `mkstemp'
/usr/lib/libMagick.a(magick_libMagick_la-utility.o): In function `ExpandFilename':
(.text+0x1c67): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(GetDflt.o): In function `GetHomeDir':
(.text+0x9a): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(GetDflt.o): In function `GetHomeDir':
(.text+0xd4): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libxml2.a(nanohttp.o): In function `xmlNanoHTTPConnectHost':
(.text+0xa4c): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(x11_trans.o): In function `_X11TransSocketUNIXConnect':
(.text+0xd82): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(x11_trans.o): In function `_X11TransSocketINETConnect':
(.text+0x1da4): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libMagick.a(ltdl.o): In function `sys_dl_sym':
(.text+0x34c5): undefined reference to `dlsym'
/usr/lib/libMagick.a(ltdl.o): In function `sys_dl_sym':
(.text+0x34e1): undefined reference to `dlerror'
/usr/lib/libMagick.a(ltdl.o): In function `sys_dl_close':
(.text+0x3519): undefined reference to `dlclose'
/usr/lib/libMagick.a(ltdl.o): In function `sys_dl_close':
(.text+0x3524): undefined reference to `dlerror'
/usr/lib/libMagick.a(ltdl.o): In function `sys_dl_open':
(.text+0x3567): undefined reference to `dlopen'
/usr/lib/libMagick.a(ltdl.o): In function `sys_dl_open':
(.text+0x3581): undefined reference to `dlerror'
/usr/lib/libX11.a(ConnDis.o): In function `_X11TransConnectDisplay':
(.text+0xaad): undefined reference to `XauDisposeAuth'
/usr/lib/libX11.a(ConnDis.o): In function `_X11TransConnectDisplay':
(.text+0xcbf): undefined reference to `XauGetBestAuthByAddr'
/usr/lib/libX11.a(ConnDis.o): In function `_X11TransConnectDisplay':
(.text+0xee2): undefined reference to `XdmcpWrap'
/usr/lib/libX11.a(CrGlCur.o): In function `open_library':
(.text+0x3d): undefined reference to `dlopen'
/usr/lib/libX11.a(CrGlCur.o): In function `fetch_symbol':
(.text+0x6b): undefined reference to `dlsym'
/usr/lib/libX11.a(CrGlCur.o): In function `fetch_symbol':
(.text+0x88): undefined reference to `dlsym'
collect2: ld returned 1 exit status
make: *** [Transform] Error 1
So, how do I make it work.
Without the static switch, it compiles fine, but it is requires libraries at runtime.
In order to be very sure that the program is statically compiled, I used --static switch.
g++ Transform.cpp --static `Magick++-config --cppflags --cxxflags --ldflags --libs` -o "Transform"
This was the result:
Transform.cpp:11:2: warning: no newline at end of file
/usr/lib/libjasper.a(jas_stream.lo): In function `jas_stream_tmpfile':
(.text+0x376): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
/usr/lib/libMagick.a(magick_libMagick_la-delegate.o): In function `AcquireTemporarySymlink':
(.text+0x2b5): warning: the use of `tempnam' is dangerous, better use `mkstemp'
/usr/lib/libMagick.a(magick_libMagick_la-utility.o): In function `ExpandFilename':
(.text+0x1c67): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(GetDflt.o): In function `GetHomeDir':
(.text+0x9a): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(GetDflt.o): In function `GetHomeDir':
(.text+0xd4): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libxml2.a(nanohttp.o): In function `xmlNanoHTTPConnectHost':
(.text+0xa4c): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(x11_trans.o): In function `_X11TransSocketUNIXConnect':
(.text+0xd82): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libX11.a(x11_trans.o): In function `_X11TransSocketINETConnect':
(.text+0x1da4): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/libMagick.a(ltdl.o): In function `sys_dl_sym':
(.text+0x34c5): undefined reference to `dlsym'
/usr/lib/libMagick.a(ltdl.o): In function `sys_dl_sym':
(.text+0x34e1): undefined reference to `dlerror'
/usr/lib/libMagick.a(ltdl.o): In function `sys_dl_close':
(.text+0x3519): undefined reference to `dlclose'
/usr/lib/libMagick.a(ltdl.o): In function `sys_dl_close':
(.text+0x3524): undefined reference to `dlerror'
/usr/lib/libMagick.a(ltdl.o): In function `sys_dl_open':
(.text+0x3567): undefined reference to `dlopen'
/usr/lib/libMagick.a(ltdl.o): In function `sys_dl_open':
(.text+0x3581): undefined reference to `dlerror'
/usr/lib/libX11.a(ConnDis.o): In function `_X11TransConnectDisplay':
(.text+0xaad): undefined reference to `XauDisposeAuth'
/usr/lib/libX11.a(ConnDis.o): In function `_X11TransConnectDisplay':
(.text+0xcbf): undefined reference to `XauGetBestAuthByAddr'
/usr/lib/libX11.a(ConnDis.o): In function `_X11TransConnectDisplay':
(.text+0xee2): undefined reference to `XdmcpWrap'
/usr/lib/libX11.a(CrGlCur.o): In function `open_library':
(.text+0x3d): undefined reference to `dlopen'
/usr/lib/libX11.a(CrGlCur.o): In function `fetch_symbol':
(.text+0x6b): undefined reference to `dlsym'
/usr/lib/libX11.a(CrGlCur.o): In function `fetch_symbol':
(.text+0x88): undefined reference to `dlsym'
collect2: ld returned 1 exit status
make: *** [Transform] Error 1
So, how do I make it work.
Without the static switch, it compiles fine, but it is requires libraries at runtime.
Re: Static Linking of ImageMagik
To have a full static distribution of ImageMagick you not only need to build ImageMagick statically but also any library it links to (i.e. jpeg, png, X11, etc.).
Re: Static Linking of ImageMagik
Static linking is beyond the scope of this discussion server since it has little to do with ImageMagick and mostly to do with compiler / linking issues. You may want to seek advice from the gcc or Linux user forums.
Re: Static Linking of ImageMagik
Ok, thank you. However, I will report if my issue is solved.
Re: Static Linking of ImageMagik
If I execute these command to make static build of ImageMagick
>>cd ImageMagick-6.4.4
>>./configure --disable-shared
>>make
>>make install
I get the following errors during compile time in my C++ code with which I am linking Magick++. The error is list is too long, and I just pasted a small snippet of it. Any solutions?
coders/xwd.c:279: référence indéfinie vers « XInitImage »
/users/etu/recherche/vnarayan/vnarayan_data/Magic_Installations/Static/lib/libMagickCore.a(magick_libMagickCore_la-compress.o): dans la fonction « Huffman2DEncodeImage »:
magick/compress.c:993: référence indéfinie vers « TIFFOpen »
magick/compress.c:1007: référence indéfinie vers « TIFFGetField »
magick/compress.c:1009: référence indéfinie vers « TIFFNumberOfStrips »
magick/compress.c:1027: référence indéfinie vers « TIFFGetFieldDefaulted »
magick/compress.c:1028: référence indéfinie vers « TIFFNumberOfStrips »
magick/compress.c:1030: référence indéfinie vers « TIFFReadRawStrip »
magick/compress.c:1033: référence indéfinie vers « TIFFReverseBits »
magick/compress.c:1037: référence indéfinie vers « TIFFClose »
magick/compress.c:1016: référence indéfinie vers « TIFFClose »
collect2: ld returned 1 exit status
>>cd ImageMagick-6.4.4
>>./configure --disable-shared
>>make
>>make install
I get the following errors during compile time in my C++ code with which I am linking Magick++. The error is list is too long, and I just pasted a small snippet of it. Any solutions?
coders/xwd.c:279: référence indéfinie vers « XInitImage »
/users/etu/recherche/vnarayan/vnarayan_data/Magic_Installations/Static/lib/libMagickCore.a(magick_libMagickCore_la-compress.o): dans la fonction « Huffman2DEncodeImage »:
magick/compress.c:993: référence indéfinie vers « TIFFOpen »
magick/compress.c:1007: référence indéfinie vers « TIFFGetField »
magick/compress.c:1009: référence indéfinie vers « TIFFNumberOfStrips »
magick/compress.c:1027: référence indéfinie vers « TIFFGetFieldDefaulted »
magick/compress.c:1028: référence indéfinie vers « TIFFNumberOfStrips »
magick/compress.c:1030: référence indéfinie vers « TIFFReadRawStrip »
magick/compress.c:1033: référence indéfinie vers « TIFFReverseBits »
magick/compress.c:1037: référence indéfinie vers « TIFFClose »
magick/compress.c:1016: référence indéfinie vers « TIFFClose »
collect2: ld returned 1 exit status
Re: Static Linking of ImageMagik
Try installing ImageMagick 6.4.5-9, the latest release. It has updated configure files that may make a difference. On our systems with 6.4.5-9 and the --disable-shared option, ImageMagick builds and installs without complaint.
Re: Static Linking of ImageMagik
Thanks, I will try this in a couple of hours and report back