首页 > 解决方案 > 尝试使用属性时的 Magick++ 链接错误

问题描述

使用Visual Studio 2017 Community Edition经过验证的C++代码,在尝试编译和链接 WindowsC++窗体应用程序时出现链接错误。

我正在尝试使用 Magick++ 属性方法从 jpeg 图像文件中获取 exif 数据,但我得到图像对象实例属性的链接错误 LNK2028 和 LNK2019。ImageMagick 的版本是使用 Magick++ 头文件编译的 6.9.3-7。操作系统是 Windows 10。尝试使用类似编译的最新 Windows 版本的 Image Magick 时,我遇到了同样的问题。

exif 数据通过 Windows 命令行 indentify -verbose 文件名存在。

我正在使用的 Magick++ 方法,例如读取、质量、调整大小和写入所有链接并且工作正常,但属性不能 - (标准字符串)extracted_data = image.attribute("exif:DateTime"); 给出链接错误。

如果我注释掉包含 image.attribute 语句的代码块,程序将编译、链接并执行 OK。

在单独的 Windows 7 PC 上,相同的 C++ 代码可以完美地编译、链接和执行。在该 PC 上,IDE 是带有 ImageMagick 6.8.6 的 Visual Studio 2010 Express。

根据上述尝试了不同版本的 ImageMagick。

Magick::InitializeMagick(NULL);
Magick::Image image;        // create an instance of the Magick::Image class
image.read(std_input_file_name);    // read the selected jpg file into the image object 
... develop the resize parameters (not shown)
image.resize(Magick::Geometry(int_output_width, int_output_height));
... the above works fine.
... but if I include:
std::string extracted_data, date_time_data;
extracted_data = image.attribute("exif:DateTimeOriginal");
... I get the linkage errors    

没有指示编译错误。

我试图摆脱两个链接错误: LNK2028 unresolved token (0A00079D) "public: class std::basic_string,class std::allocator > __thiscall Magick::Image::attribute(class std::basic_string,class std::allocator >)" (?attribute@Image@Magick@@$$FQAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V34@ @Z) 在函数“private: void __clrcall UseLIB::Form1::btnStart_Click(class System::Object ^,class System::EventArgs ^)”中引用 (?btnStart_Click@Form1@UseLIB@@$$FA$AAMXP$AAVObject @System@@P$AAVEventArgs@4@@Z)

和 LNK2019 未解析的外部符号“public: class std::basic_string,class std::allocator > __thiscall Magick::Image::attribute(class std::basic_string,class std::allocator >)” (?attribute@Image@Magick @@$$FQAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V34@@Z) 在函数“private: void __clrcall UseLIB:: Form1::btnStart_Click(类 System::Object ^,类 System::EventArgs ^)" (?btnStart_Click@Form1@UseLIB@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)

任何建议将不胜感激,并在期待中感谢您。

标签: visual-studio-2017magick++

解决方案


这个问题原来是由于一台 PC 上的 ImageMagick 版本冲突。并确保在环境变量中正确设置了 MAGICK_CORE。一旦我整理好程序,编译、链接和执行就OK了。


推荐阅读