尝试在Visual Studio编译器中尝试将ImageMagick用作静态库时出现链接器错误
已经在此处,但是由于我有更多细节要提供,我认为最好从一个新的问题开始.
This question has already been asked here, but since I have many more details to provide, I think it is best to start with a new question.
我在使用Visual Studio MSVC 2015编译器的程序中链接ImageMagick lib文件时遇到问题.这是我遵循的步骤:
I have trouble linking the ImageMagick lib files in my program that uses the Visual Studio MSVC 2015 compiler. Here are the steps I have followed:
-
我已经使用"configure.exe"实用程序编译了静态MT运行时,并在Visual Studio中构建了它生成的解决方案"VisualStaticMT.sln".这样会在C:\ ImageMagick-6.9.3-2 \ VisualMagick \ lib中创建lib文件,例如"CORE_RL_Magick ++ _.lib".
I have compiled the static MT runtimes by using the "configure.exe" utility and built in Visual Studio the solution it generated, "VisualStaticMT.sln". This creates lib files such as "CORE_RL_Magick++_.lib" in C:\ImageMagick-6.9.3-2\VisualMagick\lib.
在我的C ++ 11程序中,与ImageMagick相关的配置是(我使用QtCreator,但使用了MSVC2015编译器):
In my C++11 program, the configuration relevant to ImageMagick is (I use QtCreator, but with the MSVC2015 compiler):
INCLUDEPATH += \
C:\ImageMagick-6.9.3-2\ImageMagick\Magick++\lib \
C:\ImageMagick-6.9.3-2\ImageMagick
LIBS += \
-lC:\ImageMagick-6.9.3-2\VisualMagick\lib\CORE_RL_Magick++_ \
-lC:\ImageMagick-6.9.3-2\VisualMagick\lib\CORE_RL_wand_ \
-lC:\ImageMagick-6.9.3-2\VisualMagick\lib\CORE_RL_magick_
QMAKE_CXXFLAGS += \
-DMAGICKCORE_HDRI_ENABLE=0 \
-DMAGICKCORE_QUANTUM_DEPTH=16
该程序的一部分包含:
#include <Magick++.h>
...
Magick::Image img;
img = Magick::Image(filename);
编译时出现链接错误:
movie.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Magick::Image::Image(void)" (__imp_??0Image@Magick@@QAE@XZ) referenced in function "public: __thiscall Frame<unsigned char>::Frame<unsigned char>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0?$Frame@E@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
movie.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Magick::Image::Image(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0Image@Magick@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "public: __thiscall Frame<unsigned char>::Frame<unsigned char>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0?$Frame@E@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
movie.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall Magick::Image::~Image(void)" (__imp_??1Image@Magick@@UAE@XZ) referenced in function "public: __thiscall Frame<unsigned char>::Frame<unsigned char>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0?$Frame@E@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
movie.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class Magick::Image & __thiscall Magick::Image::operator=(class Magick::Image const &)" (__imp_??4Image@Magick@@QAEAAV01@ABV01@@Z) referenced in function "public: __thiscall Frame<unsigned char>::Frame<unsigned char>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0?$Frame@E@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
movie.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall Magick::Image::write(long,long,unsigned int,unsigned int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,enum MagickCore::StorageType,void *)" (__imp_?write@Image@Magick@@QAEXJJIIABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@W4StorageType@MagickCore@@PAX@Z) referenced in function "public: __thiscall Frame<unsigned char>::Frame<unsigned char>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0?$Frame@E@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
movie.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: struct MagickCore::_Image const * __thiscall Magick::Image::constImage(void)const " (__imp_?constImage@Image@Magick@@QBEPBU_Image@MagickCore@@XZ) referenced in function "public: __thiscall Frame<unsigned char>::Frame<unsigned char>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0?$Frame@E@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
release\corr.exe : fatal error LNK1120: 6 unresolved externals
"dllimport"错误令我惊讶,因为我认为我正在使用的静态MT运行时"中不应包含DLL.
The "dllimport" error suprises me, as I think there should be no DLL involved with the "static MT runtimes" I am using.
关于如何解决该问题的任何想法吗?
Any idea on how I could solve the problem?
谢谢.
编辑
我尝试过的一些其他事情:
A few more things I have tried:
-
将libraires与main.cpp中的以下行链接会产生相同的错误:
Linking the libraires with the lines below in main.cpp gave the same errors:
#pragma comment(lib, "CORE_RL_Magick++_.lib")
#pragma comment(lib, "CORE_RL_wand_.lib")
#pragma comment(lib, "CORE_RL_magick_.lib")
我试图添加位于C:\ ImageMagick-6.9.3-2 \ VisualMagick \ lib中的所有27个lib文件.如果我排除CORE_RL_exr_.lib,则会收到相同的错误.如果包含此文件,则会收到其他错误提示,建议不要添加此文件:
I tried to add all the 27 lib files located in C:\ImageMagick-6.9.3-2\VisualMagick\lib. If I exclude CORE_RL_exr_.lib, I get the same error. If I include it, I get additional errors that suggest this file should not be added:
CORE_RL_exr_.lib(IexBaseExc.obj):-1: error: LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in main.obj
链接ImageMagick静态库的答案是确保还链接所有依赖的静态库!
The answer to linking the ImageMagick static libraries is to ensure you link all the dependant static libraries as well!
编译完ImageMagick静态库的解决方案后,转到"VisualMagick"文件夹(在ImageMagick克隆存储库中),然后转到"lib"文件夹,您将看到所有的 * __ DB _ *.lib
和 * _ RL _ *.lib
文件进行调试和发布.
Once you have compiled the solution for ImageMagick static libraries, go to the 'VisualMagick' folder (within the ImageMagick cloned repository) then to to the 'lib' folder there you will see all the *_DB_*.lib
and *_RL_*.lib
files for Debug and Release.
对于发布和调试,您需要在其他依赖项"部分中包含这些名称.
You need to include those names in the 'Additional Dependencies' section for both Release and Debug.
另一个关键方面是确保库是由与您自己的应用程序..(WIN32或x64)相同的编译器针对相同的平台体系结构构建的.
Another key aspect is to ensure the libraries are built by the same compiler for the same platform architecture as your own application .. (WIN32 or x64).