title: OpenSSL Linking undefined reference 'EVP_MD_CTX_new' and '...fre'
body: <p>I'm trying to use the hash algorithms provided by the openssl library.
  I have openssl and libssl-dev installed. The version is 1.1.0f.
  I try to run the example code of the openssl.org site:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  #include &lt;openssl/evp.h&gt;
  
  int main(int argc, char *argv[]){
  EVP_MD_CTX *mdctx;
  const EVP_MD *md;
  char mess1[] = "Test Message\n";
  char mess2[] = "Hello World\n";
  unsigned char md_value[EVP_MAX_MD_SIZE];
  int md_len, i;
  
  if(!argv[1]) {
      printf("Usage: mdtest digestname\n");
      exit(1);
   }
  
  md = EVP_get_digestbyname(argv[1]);
  
  if(!md) {
      printf("Unknown message digest %s\n", argv[1]);
      exit(1);
  }
  
  mdctx = EVP_MD_CTX_new();
  EVP_DigestInit_ex(mdctx, md, NULL);
  EVP_DigestUpdate(mdctx, mess1, strlen(mess1));
  EVP_DigestUpdate(mdctx, mess2, strlen(mess2));
  EVP_DigestFinal_ex(mdctx, md_value, &amp;md_len);
  EVP_MD_CTX_free(mdctx);
  
  printf("Digest is: ");
  for (i = 0; i &lt; md_len; i++)
      printf("%02x", md_value[i]);
  printf("\n");
  
  exit(0);
  }
  </code></pre>
  
  <p>I try to compile this with:</p>
  
  <pre><code> gcc digest_example.c -lcrypto -lssl
  </code></pre>
  
  <p>And the compiler gives the error:</p>
  
  <pre><code>digest_example.c:(.text+0xbc): undefined reference to `EVP_MD_CTX_new'
  digest_example.c:(.text+0x138): undefined reference to `EVP_MD_CTX_free'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>And honestly, I'm clueless. I installed and reinstalled OpenSSL 2 times from the website by compiling it. Additionally, all the other commands make no problem. Just these two. Do I have to use other libraries when linking?</p>
  
  <p>Thanks for your help.</p>