Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C++
#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>
Posted
Updated 11-Oct-11 21:00pm
v2

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) :

C++
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);
    }

}


Check the following links :

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

http://forum.pellesc.de/index.php?topic=3257.0[^]
 
Share this answer
 
Comments
candd 12-Oct-11 5:08am    
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!
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.
 
Share this answer
 
Comments
candd 12-Oct-11 5:06am    
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!
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!
 
Share this answer
 
Comments
Richard MacCutchan 12-Oct-11 5:14am    
I already explained why in my previous response; you need to add the library file (libeay32.lib) to your project's Linker properties.
candd 12-Oct-11 5:22am    
Actually, I already add the library (libeay32.lib) into my project the linker already found that library but could not find that function "MD5" and any functions in that library.
The problem may be relate to (__sdtcall (Gz)) calling convention, but I do not understand why.
Could you explain me about __stdcall ?

Thank you!
Richard MacCutchan 12-Oct-11 6:35am    
I'm not sure why you are using the /Gz option, but it may be that the MD5 library was compiled with the standard __cdecl convention. Try using the default option and see if it builds OK.
candd 12-Oct-11 6:53am    
Thank you very much for the solution. (__cdecl).
I've just change setting calling convention to __cdecl.
Now my project build successful!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900