MinGW32: Linking against ImageMagick with -static flag

蓝咒 提交于 2020-01-05 04:35:07

问题


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:


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.



来源:https://stackoverflow.com/questions/17434022/mingw32-linking-against-imagemagick-with-static-flag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!