title: md5 reference error
body: <p>I had a correctly working md5 program compiled on my mac but when I try to compile on my ubuntu distro it errors out saying:</p>
  
  <pre><code> /tmp/ccKBJiV3.o: In function `str2md5':
   md5.c:(.text+0x33): undefined reference to `MD5_Init'
   md5.c:(.text+0x5b): undefined reference to `MD5_Update'
   md5.c:(.text+0x79): undefined reference to `MD5_Update'
   md5.c:(.text+0xa2): undefined reference to `MD5_Final'
   collect2: ld returned 1 exit status
  </code></pre>
  
  <p>Below is my code for main:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include "md5.h"
  #include &lt;openssl/md5.h&gt;
  #include &lt;openssl/hmac.h&gt;
  
  int main(int argc, char *argv[]) 
  {
  char *output = str2md5(argv[1], strlen(argv[1]));
  printf("%s\n", output);
  free(output);
  return 0;
  }
  </code></pre>
  
  <p>Here is my "md5.h" file just contains the str2md5 function:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #if defined(__APPLE__)
  #  define COMMON_DIGEST_FOR_OPENSSL
  #  include &lt;CommonCrypto/CommonDigest.h&gt;
  #  define SHA1 CC_SHA1
  #else
  #  include &lt;openssl/md5.h&gt;
  #endif
  
  char *str2md5(const char *str, int length) {
  int n;
  MD5_CTX c;
  unsigned char digest[16];
  char *out = (char*)malloc(33);
  
  MD5_Init(&amp;c);
  
  while (length &gt; 0) {
      if (length &gt; 512) {
          MD5_Update(&amp;c, str, 512);
      } else {
          MD5_Update(&amp;c, str, length);
      }
      length -= 512;
      str += 512;
  }
  
  MD5_Final(digest, &amp;c);
  
  for (n = 0; n &lt; 16; ++n) {
      snprintf(&amp;(out[n*2]), 16*2, "%02x", (unsigned int)digest[n]);
  }
  
  return out;
  } 
  </code></pre>
  
  <p>I have tried to compile it with all the -l things I have found on the internet. 
  For example:</p>
  
  <pre><code> gcc -Wall -lcrypto -lssl md5.c -o md5
  </code></pre>
  
  <p>Any help to get this to work would be amazing!</p>