魔法++在 VS2010 中 - 无法解析的外部符号
我正在尝试在 VS2010 中使用 ImageMagick Magick++ 进行 C++ 项目。 我从这里安装了库: klick
然后在我的项目中,我添加了 c:/ program files/ImageMagick-6.6.6-Q16/include 到包含文件夹。然后我尝试将 Magick++ 与此代码一起使用:
#include <Magick++.h>
void main(int argc, char ** argv){
InitializeMagick(*argv);
}
但这不起作用! VS2010 返回以下错误:
error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl Magick::InitializeMagick(char const *)" (__imp_?InitializeMagick@Magick@@YAXPBD@Z)
error LNK1120: 1 unresolved externals
我做错了什么?
非常感谢您的帮助!
更新:
设置链接器->输入->附加依赖项:
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;CORE_RL_Magick++_.lib
和链接器 ->一般->其他库目录:
C:\Program Files\ImageMagick-6.6.6-Q16\lib
它仍然会导致相同的错误...
更新 2
打开 C:\Program Files\ImageMagick-6.6.6-Q16\lib 中的 .lib 文件会导致此错误:
更新 3
CORE_RL_Magick++_.lib 确实包含 ?InitializeMagick@Magick@@YAXPEBD @Z,但不是?InitializeMagick@Magick@@YAXPBD@Z。这是否意味着 .lib 文件已损坏?
更新4
我通过手动编译.lib 文件解决了我的问题。 感谢大家!
I'm trying to use ImageMagick Magick++ for a C++ Project in VS2010.
I installed the Library from here: klick
Then in my Project, I added c:/program files/ImageMagick-6.6.6-Q16/include to the include folders. Then I tried to use Magick++ with this code:
#include <Magick++.h>
void main(int argc, char ** argv){
InitializeMagick(*argv);
}
But this does not work!
VS2010 returns the following errors:
error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl Magick::InitializeMagick(char const *)" (__imp_?InitializeMagick@Magick@@YAXPBD@Z)
error LNK1120: 1 unresolved externals
What am I doing wrong?
Thanks very much for your help!
UPDATE:
Set Linker -> Input -> Additionnal Dependencies to:
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;CORE_RL_Magick++_.lib
And Linker -> General -> Additionnal Library Directories to:
C:\Program Files\ImageMagick-6.6.6-Q16\lib
It still results in the same error...
UPDATE 2
Opening the .lib files in C:\Program Files\ImageMagick-6.6.6-Q16\lib results in this error:
UPDATE 3
CORE_RL_Magick++_.lib does contain ?InitializeMagick@Magick@@YAXPEBD@Z, but not ?InitializeMagick@Magick@@YAXPBD@Z. Does this mean the .lib file is corrupted?
UPDATE 4
I solved my problem by manually compliling the .lib files.
Thanks to all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 undname.exe 实用程序,这些名称将取消修饰为:
注意参数上的 __ptr64 声明符。您有某种编译设置可以将 char* 转换为 64 位指针。就像针对 64 位操作系统编译此代码一样。但链接 32 位 .lib。这通常会生成一个关于 .lib 的位错误的链接器错误,不太确定为什么您看不到这一点。也许是 mingw 神器,不知道它是如何工作的。
Using the undname.exe utility, these names undecorate to:
Note the __ptr64 declarator you got on the argument. You've got some kind of compile setting that turns that char* into a 64-bit pointer. Like compiling this code targeting a 64-bit operating system. But linking the 32-bit .lib. This normally generates a linker error about the bit-ness of the .lib being wrong, not so sure why you don't see this. Maybe a mingw artifact, not sure how it works.
您还应该向 Visual Studio 指示用于
在链接器 -> 中进行链接的 .lib。输入->附加依赖项
编辑:并将 magick 库的路径放入
Linker -> 中一般->附加库目录
EDIT2:如果它仍然不起作用,那么您正在调用带有错误导出签名的函数。
启动 msdev 工具 Dependency Walker。并检查 magick.lib 是否确实导出了名为
?InitializeMagick@Magick@@YAXPBD@Z
的函数,我错了,它不是微软工具: dependencywalker.com/" rel="nofollow">Dependency Walker
我错了 Dependency Walker 不打开 .lib,只打开 Dll 和 Exes。
但是,由于您在.lib文件的内容中找到了
?InitializeMagick@Magick@@YAXPBD@Z
,这意味着它确实是通过这种方式导出的。EDIT3:您确定附加库的名称和文件夹正确吗?我真的想不出 Visual C++ 无法与您的库链接的另一个原因。如果您的 .lib DO 包含字符串
?InitializeMagick@Magick@@YAXPBD@Z
我真的认为它应该链接。EDIT4:您可以从文件
粘贴 InitializeMagick 的原型定义吗?有一些东西使得它在 Visual C++ 和你的库供应商之间的编译方式不同。
?InitializeMagick@Magick@@YAXPEBD@Z
和?InitializeMagick@Magick@@YAXPEBD@Z
是两个不同的签名。当包含
时,Visual C++ 对其的理解有所不同。 (这就是为什么我需要查看该函数的原型)You should also indicate to Visual Studio the .lib to be used for linking
in Linker -> Input -> Additionnal Dependencies
EDIT: and put the path of the magick library
in Linker -> General -> Additionnal Library Directories
EDIT2: if it still doesnt work, then you are calling a fonction with a wrong exported signature.
Launch the msdev tool Dependency Walker. And check if the magick.lib really exports the function whose name is
?InitializeMagick@Magick@@YAXPBD@Z
I am wrong it's not a microsoft tool: Dependency Walker
I was wrong Dependency Walker doesnt open .lib, only Dlls and Exes.
However since you have found
?InitializeMagick@Magick@@YAXPBD@Z
in the content of the .lib file, it means that it is reaaly exported this way.EDIT3: Are you SURE the name and the folder of the additionnal library is correct. I really cannot think of another reason for Visual C++ being unable to link with your library. If your .lib DO contains the string
?InitializeMagick@Magick@@YAXPBD@Z
I really think it should link.EDIT4: could you paste from the file
<Magick++.h>
the prototype definition of InitializeMagick ?there is something that makes it be compiled differently between visual c++ and your library supplier.
?InitializeMagick@Magick@@YAXPEBD@Z
and?InitializeMagick@Magick@@YAXPEBD@Z
are two DIFFERENT signatures. When including<Magick++.h>
Visual C++ understands its differently. (that's why I need to see the prototype of the function)谢谢!
附加依赖项行现在包含以下文本(查看末尾):
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;C: \Program Files\ImageMagick-6.6.6-Q16\lib\CORE_RL_Magick++_.lib
它仍然不起作用。是否是错误的 .lib 文件?
这个 .lib 文件是做什么用的?
源代码不应该工作吗?没有DLL...
Thank you!
The additional dependecies line contains now the following text (look at the end):
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;C:\Program Files\ImageMagick-6.6.6-Q16\lib\CORE_RL_Magick++_.lib
It still does not work. Is it the wrong .lib file?
what is this .lib file for?
Shouldn't source code just work? There isn't any DLL...
文档 指出:“Windows 用户可以通过手动编辑 Magick++ 演示之一的项目文件来开始使用计划”。你尝试过吗?
The documentation says: "Windows users may get started by manually editing a project file for one of the Magick++ demo programs." Did you try that?