MinGW32: Linking against ImageMagick with -static

2019-07-27 03:48发布

I am currently trying to build a Windows-version of emacs that supports ImageMagick.

For that purpose I have already compiled ImageMagick with MinGW32/MSys in order to get compatible library files. Basically linking also works, though I have to add explicitly -llibMagickCore-6.Q16 and -llibMagickWand-6.Q16 to the linking command through configure.bat's --lib option.

However, the binary distribution of emacs for windows is supposed to load, even when the dependencies are absent. This behaviour I obtain when I add the linker option (configure.bat --ldflags) -static.

However, when I try to compile with ImageMagick-Support, static linking fails saying it cannot find the ImageMagick includes.

The library files are located in D:/BUILD/libraries/lib. As a minimal example:

D:\>ld -LD:/BUILD/libraries/lib -llibMagickWand-6.Q16

D:\>ld -static -LD:/BUILD/libraries/lib -llibMagickWand-6.Q16
ld: cannot find -llibMagickWand-6.Q16

The directory does however contain the static library.

D:\BUILD\libraries\lib>dir *Magick*
[...]
2013-07-02  15:16         2,585,830 libMagick++-6.Q16.a
2013-07-02  15:16         1,745,404 libMagick++-6.Q16.dll.a
2013-07-02  15:16             1,178 libMagick++-6.Q16.la
2013-07-02  15:16         5,153,712 libMagickCore-6.Q16.a
2013-07-02  15:16           977,292 libMagickCore-6.Q16.dll.a
2013-07-02  15:16             1,096 libMagickCore-6.Q16.la
2013-07-02  15:16         1,609,692 libMagickWand-6.Q16.a
2013-07-02  15:16           472,364 libMagickWand-6.Q16.dll.a
2013-07-02  15:16             1,142 libMagickWand-6.Q16.la

Any idea, what could be going wrong here? From what I understand, the .a files are the static libraries for MinGW, so the absence of .lib files (Visual Studio) shouldn't be a problem.

I have used the Unix source distribution of ImageMagick, because the Windows sources require Visual Studio for building.

1条回答
▲ chillily
2楼-- · 2019-07-27 04:21

I found the error looking at ld -verbose=0 ....

For some reason, when using the -static flag the lookupbehaviour changes. Without the -static flag:

...
attempt to open D:/BUILD/libraries/lib/liblibMagickWand-6.Q16.dll.a failed
attempt to open D:/BUILD/libraries/lib/libMagickWand-6.Q16.dll.a succeeded

with -static flag:

...
attempt to open D:/BUILD/libraries/lib\liblibMagickWand-6.Q16.a failed
attempt to open c:\mingw\bin\../../MinGW/usr/local/lib\liblibMagickWand-6.Q16.a failed
attempt to open c:\mingw\bin\../../MinGW/lib\liblibMagickWand-6.Q16.a failed
attempt to open c:\mingw\bin\../../MinGW/usr/lib\liblibMagickWand-6.Q16.a failed
attempt to open D:/BUILD/libraries/lib\libMagickWand-6.Q16.lib failed
attempt to open c:\mingw\bin\../../MinGW/usr/local/lib\libMagickWand-6.Q16.lib failed
attempt to open c:\mingw\bin\../../MinGW/lib\libMagickWand-6.Q16.lib failed
attempt to open c:\mingw\bin\../../MinGW/usr/lib\libMagickWand-6.Q16.lib failed
ld: cannot find -llibMagickWand-6.Q16

Writing -lMagickWand-6.Q16 instead of -llibMagickWand-6.Q16 worked.

查看更多
登录 后发表回答