error LNK2019 on visual studio

hello everyone,
I try to use md5 in c/c++, working with visual studio I've hard time figuring out these errors

1>main.obj : error LNK2019: unresolved external symbol "void __cdecl MD5Init(struct MD5_CTX *)" (?MD5Init@@YAXPAUMD5_CTX@@@Z) referenced in function _WinMain@16
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl MD5Update(struct MD5_CTX *,unsigned char *,unsigned int)" (?MD5Update@@YAXPAUMD5_CTX@@PAEI@Z) referenced in function _WinMain@16
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl MD5Final(unsigned char * const,struct MD5_CTX *)" (?MD5Final@@YAXQAEPAUMD5_CTX@@@Z) referenced in function _WinMain@16

here my code :
md5.c : https://pastebin.com/6mnXp3us
md5.h : https://pastebin.com/fXvFrpQY
md5global.h : https://pastebin.com/zW3e81K8

i can't figure out the cause :(

thank you!
Last edited on
It means your project doesn't contain those functions, which suggests your project (the project with your main in) doesn't contain those files.
Read: http://www.cplusplus.com/forum/general/113904/
That explains "why".

The "how" ... as Repeater said, IDEs like Visual Studio usually have a concept of "project".
I don't get it
i have added all the files needed with Add->Existing Item

md5global.h md5.h md5.c everything...

in my main i've put on the top #include "md5.h"

this is not what your are talking about ?

this is not a static lib..!!!!
void MD5Init PROTO_LIST((MD5_CTX *));
void MD5Update PROTO_LIST((MD5_CTX *, unsigned char *, unsigned int));
void MD5Final PROTO_LIST((unsigned char[16], MD5_CTX *));

in md5.h
The error happens because md5.h was not written to be included from a C++ file. When the C++ compiler parses md5.h, it thinks it's looking at declarations for C++ functions, but when the C compiler compiles md5.c, it generates C functions.

Add
1
2
3
extern "C"{
#include "md5.h"
}
around every inclusion of md5 in a .cpp file.
thank you helios, the most useful answer
however with your solution i still have errors

1>main.obj : error LNK2019: unresolved external symbol _MD5Init referenced in function _WinMain@16
1>main.obj : error LNK2019: unresolved external symbol _MD5Update referenced in function _WinMain@16
1>main.obj : error LNK2019: unresolved external symbol _MD5Final referenced in function _WinMain@16

I'm new to c/c++ sorry if I appear dumb

anyway i figured out how to make work these functions, i renamed md5.c to .cpp and removed static before every function in md5.c and some other stuff that I don't remember now

thank you :)
you may need to make a new project. Somehow your project is set up as a GUI project, which expects winmain instead of main, but it may not be enough to just rename it. You can try it, but if it does not work you may need a new project with console program settings instead of windows/gui settings. Its fixable, but IIRC it takes like flipping a dozen project setting variables by hand which I don't even remotely begin to remember what they were.

are you on a 16 bit machine ??
Last edited on
'_WinMain@16' is the function that uses the symbol, not the missing symbol.
@16 is the mangled part of the symbol. It has nothing to do with the system's bitness.

I really don't get you, man. Sometimes you say smart things, and other times you just waltz into a thread and spout some nonsense that just adds noise and doesn't contribute anything of value. What's your deal? Are you trolling?
what do you mean but "mangled part"?

yes I'm currently developing for 16 bit but I'm not on a 16 bit machine this is why sometime I have code errors

but yeah to conclude I still don't get the answer of @Repeater & @keskiverto don't get what they wanted to say

thanks all
Last edited on
The reason why the "unresolved symbol" error occurs is that the object file/library that contains (the implementation of the code represented by) the needed symbol is not included in the linking process.

One can call compiler and linker from command line.
One can manually write a "Makefile" that has commands to call compiler and linker.
One can create a "project file" that some build tool uses to write a Makefile. (MSVS both creates and is a build tool.)
Which ever method you use, there is a chance to forget to add all necessary files.

Ok, we did double-check that all files are involved.
It is still possible to forget to write implementation for some function.

Then remains a mismatch between function declaration and implementation. For a class member function that creates a compiler error, but with standalone functions linker has to deal with it. You seem to have this case, rather than the first.


We (and compiler) see in our code function declarations with name and argument types. The object file has a "symbol". The symbol is computed from declaration, but for nextafter( double, double ) it will not look like "nextafter(double,double)".
The string is "mangled", encoded.

There are tools to list symbols that an object file has, and they should have an option to show the symbols demangled back to human-readable strings.

For example, your linker did show both unmangled and mangled versions:
1
2
"void __cdecl MD5Update(struct MD5_CTX *,unsigned char *,unsigned int)"
(?MD5Update@@YAXPAUMD5_CTX@@PAEI@Z)  // mangled 

The name looks identical. struct MD5_CTX * seems to match @YAXPAUMD5_CTX, etc.
Last edited on
Registered users can post here. Sign in or register to post.