8
#include <openssl/md5.h>
void mMD5(unsigned char * packet, int size) {

    unsigned char* res;

    MD5((unsigned char*)&packet, size, (unsigned char*)&res);

    for(int i=0; i<MD5_DIGEST_LENGTH; i++) {
        printf("%02x", res[i]);
    }
}

I get the error: undefined reference to MD5

Can anyone help me?

jww
  • 97,681
  • 90
  • 411
  • 885
Bewn
  • 575
  • 4
  • 9
  • 13

1 Answers1

13

You need to link to the matching library. You should have a file called md5.lib or md5.a or something like that (depending on your OS), and add it to your linker command line (again, depending on your environment).

Asaf
  • 4,317
  • 28
  • 48
  • 13
    In gcc, it's `-lssl -lcrypto`. – csl Mar 20 '12 at 19:26
  • thanks ! it work't! But, do you know how to put set the link options in eclipse? – Bewn Mar 20 '12 at 19:47
  • I don't really use eclipse, but I imagine you should find it somewhere in the workspace's linker options (or something like that). – Asaf Mar 20 '12 at 20:04
  • Many thanks my friend! I found how to do it in eclipse to. :) – Bewn Mar 21 '12 at 21:25
  • Would you know how it is for PostgreSQL? I am having the same problem while writing C code for MD5 in PSQL. But the answer does not help. – student001 Apr 11 '14 at 09:01
  • For those who are looking to do this in eclipse, it's Right Click Project -> C/C++ Build Settings -> Tool Settings -> GCC C Linker -> Libraries and then add ssl and crypto in the -l section on the right. – stanri Jun 02 '16 at 08:11