Click to See Complete Forum and Search --> : Md5
Charred_Phoenix
04-04-2003, 07:20 AM
To make and print an md5 hash, I should just have to do something like this:
#include <stdio.h>
#include <openssl/md5.h>
int main(void) {
char heeble[14];
md5("HEEBLE", 6, heeble);
printf("%s\n", heeble);
return 0;
}
Right? But when I do that I get an undefined reference to md5, do I need to link to something?
binaryDigit
04-04-2003, 10:36 AM
i don't know the answer to this one but i'd definitely like to see more information about this.
any links to docs, manpages, ...??
bwkaz
04-04-2003, 10:58 AM
You probably need to link -lssl or -lopenssl, yes. Check the OpenSSL docs to see what the library's name is for sure.
Charred_Phoenix
04-05-2003, 12:02 AM
I looked in the docs, but can't find the relevant info :(
bwkaz
04-05-2003, 10:33 AM
Really... that's odd.
Well, try -lopenssl first (those are ell's, BTW, even though they might look like capital i's ;)), and then -lssl if that doesn't work.
Charred_Phoenix
04-07-2003, 03:25 AM
I know what they are, but they don't work :(
bwkaz
04-07-2003, 09:28 AM
"they don't work"
OK, ... so what are the errors?
binaryDigit
04-07-2003, 01:37 PM
after browsing some of the docs i'm seeing this:
-lssl -lcrypto
you may also have to specify the include directory for the ssl headers.
i.e.
gcc -I/usr/local/ssl/include -L /usr/local/ssl/lib -lssl -lcrypto
of course /usr/local/ssl may not be the directory you have the libs and includes installed in. you should probably know that first.
Charred_Phoenix
04-11-2003, 05:36 AM
[Charred@dhcp-9-139 md5]$ gcc -o md5 -lcrypto md5.c
/tmp/ccJKfojw.o: In function `main':
/tmp/ccJKfojw.o(.text+0x1f): undefined reference to `md5'
collect2: ld returned 1 exit status
[Charred@dhcp-9-139 md5]$ man md5
[Charred@dhcp-9-139 md5]$ gcc -o md5 -lssl md5.c
/tmp/ccGZM1WI.o: In function `main':
/tmp/ccGZM1WI.o(.text+0x1f): undefined reference to `md5'
collect2: ld returned 1 exit status
[Charred@dhcp-9-139 md5]$
:-/
binaryDigit
04-11-2003, 08:44 AM
where are your libraries installed? are they in your path?
bwkaz
04-11-2003, 09:31 AM
How about gcc -o md5 md5.c -lssl -lcrypto, since you need to actually tell it to use both the crypto and ssl libraries?
If you notice, that was how binaryDigit's examples were all set up...
Also, you can do a locate libssl.so (assuming your locate database is up to date -- do an updatedb if it isn't), then put the directory that libssl.so is in on the gcc command line. Like gcc -o md5 md5.c -L/path/to/wherever/it/was -lssl -lcrypto
You can do the same with libcrypto.so (the locate, that is), and put that directory, if it's different, in another -L switch.
Charred_Phoenix
04-12-2003, 12:24 AM
[Charred@dhcp-9-139 md5]$ gcc -o md5 -L /usr/lib/libssl.so -L /usr/lib/libcrypto.so -lssl -lcrypto md5.c
/tmp/cciRMdKg.o: In function `main':
/tmp/cciRMdKg.o(.text+0x1f): undefined reference to `md5'
collect2: ld returned 1 exit status
[Charred@dhcp-9-139 md5]$
bwkaz
04-12-2003, 10:03 AM
gcc -o md5 -L /usr/lib/libssl.so -L /usr/lib/libcrypto.so -lssl -lcrypto md5.c What the heck is this? The -L flag tells gcc "the next thing is a directory to look for libraries in", not "the next thing is a library". You should probably get rid of those -L's completely (yes, both of them), and just use -lssl -lcrypto. My comment in the last post was for if they weren't in somewhere standard, like /usr/lib. They are in /usr/lib, so ignore the comment about -L in my last post.
The other thing is, if you look at the manpage for md5, it's not actually called md5. It's called MD5. Uppercase your function, and make sure that you're passing it the right stuff -- man 5 md5 to find out the syntax of the function call.
Charred_Phoenix
04-23-2003, 02:25 AM
same thing happens with uppercase....
bwkaz
04-23-2003, 09:26 AM
Whoops, that should've been man 3 md5, not man 5 md5. :o
Anyway, that's funny, because it works for me:
[bilbo@beta bilbo]$ cat <<EOF >test.c
> #include <stdio.h>
> #include <openssl/md5.h>
>
> int main(void) {
>
> char heeble[14];
> md5("HEEBLE", 6, heeble);
>
> printf("%s\n", heeble);
>
> return 0;
> }
> EOF
[bilbo@beta bilbo]$ gcc -o test test.c -lssl -lcrypto
/tmp/ccOAixcZ.o: In function `main':
/tmp/ccOAixcZ.o(.text+0x27): undefined reference to `md5'
collect2: ld returned 1 exit status
[bilbo@beta bilbo]$ gvim test.c # ******
[bilbo@beta bilbo]$ gcc -o test test.c -lssl -lcrypto
[bilbo@beta bilbo]$ ./test
â!å<ÿ¡SA^vðö@äb(@ùÿ¿¡@
[bilbo@beta bilbo]$ The # ****** is where I edited the file and changed md5 to MD5. After that, as you can see, it compiled just fine...
Charred_Phoenix
04-23-2003, 07:43 PM
Oh well, I don't know, i'll play with it later today and see what happens.