VC ++ 2008错误LNK2019:引用了未解析的外部符号_MD5 @ 12 [英] VC++2008 error LNK2019: unresolved external symbol _MD5@12 referenced

查看:115
本文介绍了VC ++ 2008错误LNK2019:引用了未解析的外部符号_MD5 @ 12的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用vc ++ 2008构建C项目.
在这个项目中,我使用openssl库的MD5函数.
但是我有一个错误LNK2019 _MD5 @ 12参考.
我已经检查并确保库中包含"MD5"功能
"libeay32.lib".
(我已经将其他库目录"配置为指向"libeay32.lib"的路径.
但是我不明白为什么我不能在代码中使用功能MD5.
任何人都可以帮助我找出原因.
非常感谢!

P/s:
这是我的C代码:

Hi,

I am using vc++2008 to build a C project.
In this project, I use MD5 function of openssl library.
But I have an error LNK2019 _MD5@12 reference.
I already check and sure that the "MD5" function is include in the library
"libeay32.lib".
(I already configure the "Additional Library Directory" to path to the "libeay32.lib".
But I don''t understand why I could not use the function MD5 in my code.
Could any body help me to find out the cause.

Thank you very much!

P/s:
Here is my C Code:

#include <stdio.h>
#include <stdlib.h>
#include <openssl\md5.h>

int __cdecl main(int argc, char *argv[])
{
    HINSTANCE hinstLib = LoadLibrary(TEXT("libssl32.dll"));
    unsigned char *input = "abc";
    unsigned char *md5;
    size_t n = 3;

    MD5(input, n, md5);


}</stdlib.h></stdio.h>

推荐答案

您的代码正常工作,请参见下文(假设MD5是加载的库中的函数):

You have to get the address of the function with GetProcAddress for your code to work, see below (assuming MD5 is a function in the library loaded) :

int __cdecl main(int argc, char *argv[])
{
    HINSTANCE hinstLib = LoadLibrary(TEXT("libssl32.dll"));
    if(hinstLib != NULL)
    {
       FARPROC MD5;
       unsigned char *input = "abc";
       unsigned char *md5;
       size_t n = 3;
       MD5 = GetProcAddress ( hinstLib , "MD5" ) ;
       MD5(input, n, md5);
    }

}



检查以下链接:

http://en.wikipedia.org/wiki/Dynamic-link_library [ http://forum.pellesc.de/index.php?topic=3257.0 [ ^ ]



Check the following links :

http://en.wikipedia.org/wiki/Dynamic-link_library[^]

http://forum.pellesc.de/index.php?topic=3257.0[^]


您应该不是以这种方式使用LoadLibrary()函数,而是将库包含在您的项目中.只需将库名称( libeay32.lib )添加到项目的链接器属性中的正确条目即可.还要确保关联的DLL与EXE文件位于同一目录中,或者位于系统PATH变量中的目录之一中.
You should not be using the LoadLibrary() function in this way, but including the library in your project. Just add the library name (libeay32.lib) to the correct entry in your project''s Linker properties. Also make sure the associated DLL is either in the same directory as your EXE file or in one of the directories in your system''s PATH variable.


非常感谢您的答复在我的问题上.
>您不应该以这种方式使用LoadLibrary()函数
抱歉,因为我上传了错误的源代码.
实际上是我的波纹管源代码:

#include< stdio.h>
#include< stdlib.h>

#include< openssl \ md5.h>

int __cdecl main(int argc,char * argv [])
{
unsigned char * input ="abc";
未签名的字符* md5;
size_t n = 3;
MD5(input,n,md5);

}

函数"MD5"已经在库"libeay32.lib"中定义.
但是当我将其链接到Win32项目(__stdcall(/Gz)调用约定)时.
波纹管链接器错误发生.

1>正在链接...
1> LINK:上一个增量链接未找到或未构建.\ Debug \ trfs.exe;执行完整链接
1> trfs_main.obj:错误LNK2019:函数_main
中引用的未解析的外部符号_MD5 @ 12 1>.\ Debug \ trfs.exe:致命错误LNK1120:1未解决的外部因素

我不明白为什么发生此链接器错误.
您能否重新检查问题并找到适合我的解决方案!

谢谢!
Thank yous very much for answering on my question.
> You should not be using the LoadLibrary() function in this way
Sorry because I uploaded the wrong source code.
actually my source code as bellows:

#include <stdio.h>
#include <stdlib.h>

#include <openssl\md5.h>

int __cdecl main(int argc, char *argv[])
{
unsigned char *input = "abc";
unsigned char *md5;
size_t n = 3;
MD5(input, n, md5);

}

The function "MD5" already was defined in the library "libeay32.lib".
But when I linked it in to a Win32 project ( __stdcall (/Gz) calling convention).
The bellow linker error happened .

1>Linking...
1>LINK : .\Debug\trfs.exe not found or not built by the last incremental link; performing full link
1>trfs_main.obj : error LNK2019: unresolved external symbol _MD5@12 referenced in function _main
1>.\Debug\trfs.exe : fatal error LNK1120: 1 unresolved externals

I could not understand why this linker error happened.
Could you please re-check the problem and find the solution for me!

Thank you!


这篇关于VC ++ 2008错误LNK2019:引用了未解析的外部符号_MD5 @ 12的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆