简体   繁体   English

如何将 Imagemagick 库链接到 Qt(windows)

[英]How to Link Imagemagick library to Qt(windows)

I have developed an application with mac and for one month now, Im trying to link Qt with ImageMagick on windows.我已经用 mac 开发了一个应用程序,现在一个月了,我试图将 Qt 与 Windows 上的 ImageMagick 链接起来。

I just cant find the files and the version of Imagemagick library that need to be linked to Qt in order to make my application work on windows.我只是找不到需要链接到 Qt 以使我的应用程序在 Windows 上运行的文件和 Imagemagick 库的版本。

I have tried most of the libraries from here我已经尝试了这里的大部分库

Thats the only thing I added to the .pro file while I was developing on a mac这是我在 mac 上开发时添加到 .pro 文件的唯一内容

INCLUDEPATH += . /opt/local/include/ImageMagick
LIBS += -L/opt/local/lib -lMagick++

When I add this to my .pro当我将它添加到我的 .pro 时

INCLUDEPATH += C:/im6/include/ImageMagick
LIBS += C:/im6/lib/libMagickWand.a
LIBS += C:/im6/lib/libMagick++.a
LIBS += C:/im6/lib/libMagickCore.a
C:/im6/lib/libMagick++.a

I get 10.000 + simmilar errors to that:我得到 10.000 + 类似的错误:

(Image.o):C:\msys\1.0\home\cristy\ImageMagick-6.6.6-0/Magick++/lib/Image.cpp:4157: undefined reference to `__gxx_personality_sj0'
    
    C:/im6/lib/libMagick++.a(Image.o):C:\msys\1.0\home\cristy\ImageMagick-6.6.6-0/Magick++/lib/Image.cpp:4157: undefined reference to `_Unwind_SjLj_Register'
    
    C:/im6/lib/libMagick++.a(Image.o):C:\msys\1.0\home\cristy\ImageMagick-6.6.6-0/Magick++/lib/Image.cpp:4178: undefined reference to `_Unwind_SjLj_Unregister'

For more errors check this有关更多错误,请检查

Has anyone tried to build and deploy an ImageMagick application using qt on windows ?有没有人尝试在 Windows 上使用 qt 构建和部署 ImageMagick 应用程序? Which files do I need to link while building and which files while deploying ?构建时需要链接哪些文件,部署时需要链接哪些文件?

  1. The error message tells me that you use mingw (with qtcreator).错误消息告诉我您使用了 mingw(使用 qtcreator)。 Your library might not work with this compiler.您的库可能不适用于此编译器。 You need a mingw version of the library, probably named libmagick.a.您需要一个 mingw 版本的库,可能名为 libmagick.a。

  2. LIBS += -L$$quote(c:/Program Files/ImageMagick-6.6.5-Q16/lib) -lmagick (see the documentation about qmake Project Files LIBS += -L$$quote(c:/Program Files/ImageMagick-6.6.5-Q16/lib) -lmagick(请参阅有关qmake 项目文件的文档

Please go get ImageMagick source package.请去获取 ImageMagick 源码包。

I can't give direct instructions how to work with MinGW of Qt Creator, but basically following.我无法直接说明如何使用 Qt Creator 的 MinGW,但基本上遵循。 I prefer to use qtvars.bat that comes with binary distributions of Qt to set environment.我更喜欢使用 Qt 二进制发行版附带的 qtvars.bat 来设置环境。

  1. Open Windows cmd打开 Windows cmd
  2. Set PATH to have /path/to/mingw/bin and /path/to/qt/bin before other paths将 PATH 设置为 /path/to/mingw/bin 和 /path/to/qt/bin 在其他路径之前
  3. Go to directory where you have extracted ImageMagick source转到您提取 ImageMagick 源代码的目录
  4. read README, INSTALL and such to compile the ImageMagick (most likely just ./configure ; mingw32-make, but never be sure)阅读 README、INSTALL 等以编译 ImageMagick(很可能只是 ./configure ; mingw32-make,但永远不要确定)
  5. Edit your .pro file with something like LIBS += -L$$quote(/path/to/imagemagick/lib/dir) -lmagick .使用 LIBS += -L$$quote(/path/to/imagemagick/lib/dir) -lmagick 之类的内容编辑您的 .pro 文件。 The lib may be in bin dir or in lib dir. lib 可能在 bin dir 或 lib dir 中。 See hmuelner's answer for more information.有关更多信息,请参阅 hmuelner 的回答。

At this point, the configuration should be ready.此时,配置应该准备好了。 Compilation at Qt Creator should work, but you can as well use this cmd windows to compile your program: go to program directory, run “qmake” and “mingw32-make”.在 Qt Creator 上编译应该可以工作,但您也可以使用这个 cmd windows 来编译您的程序:转到程序目录,运行“qmake”和“mingw32-make”。

You cannot link against a ImageMagick++ library built with MSVC, as mingw and MSVC DLLs are incompatible for C++ libraries.您不能链接到使用 MSVC 构建的 ImageMagick++ 库,因为 mingw 和 MSVC DLL 与 C++ 库不兼容。 You can't link a MSVC-built C++ library into a mingw project, nor vice versa.您不能将 MSVC 构建的 C++ 库链接到 mingw 项目,反之亦然。 C-only libraries work fine. C-only 库工作正常。 Also, according to this fortum thread , using builds against old mingw-versions with current mingw versions doesn't work as the exception handling changed (as you get more errors than that, I wouldn't expect that to be the only problem though).此外,根据这个fortum线程,使用当前mingw版本的旧mingw版本构建不起作用,因为异常处理发生了变化(因为你得到的错误比这更多,但我不希望这是唯一的问题) . If there is no binary package for your mingw version (and I don't see any on the imagemagick website), your only option is to use a source package, as Smar suggests.如果您的 mingw 版本没有二进制包(而且我在 imagemagick 网站上没有看到任何二进制包),您唯一的选择是使用源包,正如 Smar 建议的那样。

Another option of course is to install Visual Studio, download Qt for MSVC and build your project with MSVC.当然,另一种选择是安装 Visual Studio,下载 Qt for MSVC 并使用 MSVC 构建您的项目。

I have found that the minGW tool set is very much treated as a "stepchild" in the Windows world.我发现 minGW 工具集在 Windows 世界中被视为“继子”。 I know it doesn't help your particular situation, but we had numerous problems with third-party libs while trying to use Qt with minGW.我知道这对您的特定情况没有帮助,但是在尝试将 Qt 与 minGW 一起使用时,我们在第三方库方面遇到了很多问题。 There were always extra steps, or non-existent build instructions that we had to figure out or tweak.总是有额外的步骤,或者我们必须弄清楚或调整不存在的构建指令。

Once we switched to the MSVC version, all of those problems went away.一旦我们切换到 MSVC 版本,所有这些问题都消失了。 Note that this doesn't mean you have to use Visual Studio (you can still use Qt creator), it just means that the Visual Studio compiler is being used.请注意,这并不意味着您必须使用 Visual Studio(您仍然可以使用 Qt creator),这仅意味着正在使用 Visual Studio 编译器。 You can get the compiler for free using the Platform SDK.您可以使用 Platform SDK 免费获得编译器。 If this is an option, you might save yourself a lot of pain by switching now.如果这是一个选项,您现在可以通过切换来为自己省去很多痛苦。 It's unfortunate, but that is just the current status quo, at least as we discovered.不幸的是,这只是目前的现状,至少正如我们发现的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM