# C99: md5



## graudeejs (Apr 17, 2010)

I don't understand why this doesn't compile

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

#include <sys/types.h>
#include <md5.h>

int main(int argc, char **argv) {
	MD5_CTX md5;
	MD5Init(&md5);

	char test[]="test";
	MD5Update(&md5, test, strlen(test));

	char *res = MD5End(&md5, NULL);

	printf("%s\n", res);

	free(res);
	return 0;
}
```


```
killasmurf86 $ make
cc -O2 -pipe -march=pentiumpro -Wall -std=c99 -g passwd.c -o test
/var/tmp//ccKahwVY.o(.text+0x23): In function `main':
/home/killasmurf86/src/c/sd_prog/src/passwd.c:12: undefined reference to `MD5Init'
/var/tmp//ccKahwVY.o(.text+0x4d):/home/killasmurf86/src/c/sd_prog/src/passwd.c:15: undefined reference to `MD5Update'
/var/tmp//ccKahwVY.o(.text+0x5b):/home/killasmurf86/src/c/sd_prog/src/passwd.c:17: undefined reference to `MD5End'
*** Error code 1

Stop in /home/killasmurf86/src/c/sd_prog/src.
```
I just don't get it, I included md5.h and sys/types.h, why i see this ^^^


----------



## crsd (Apr 17, 2010)

-lmd ?


----------



## graudeejs (Apr 18, 2010)

aaaaaaaaaaaaa, that was so easy....
One thing I don't understand, hod you you figure out name of library you need to link with, if header name is different.... this is big booger to me

For example you inlcude <libpq-fe.h> (PostgreSQL) and link against *pq*
Why suck a cryptology?

man also doesn't say, against shich lib I need to link... it might as well be md5


----------



## crsd (Apr 18, 2010)

That one was from manpage  :

```
NAME
     MD5Init, MD5Update, MD5Pad, MD5Final, MD5End, MD5File, MD5FileChunk,
     MD5Data â€” calculate the RSA Data Security, Inc., â€˜â€˜MD5â€™â€™ message digest

[B]LIBRARY
     Message Digest (MD4, MD5, etc.) Support Library (libmd, -lmd)[/B]
```


----------



## graudeejs (Apr 18, 2010)

crsd said:
			
		

> That one was from manpage  :
> 
> ```
> NAME
> ...



Holy shit. It was right on top of manpage..... how the hell did I miss it. lol
Thank you very much, I owe you a beer


----------



## Carpetsmoker (Apr 18, 2010)

Another method:


```
[/lib]% grep MD5End *
Binary file libmd.so.4 matches
```

And ofcourse:
http://www.google.nl/search?client=opera&rls=en&q=MD5End&sourceid=opera&ie=utf-8&oe=utf-8


----------

