title: Linking errors (collect2: ld returned 1)
body: <p>Ok, So I've been going through the various cases for this error and so far I have not been able to figure out exactly what is causing it this time (I am a little dyslexic, so apologies if it is staring me in the face) I keep finding references to problems like this: <a href="https://stackoverflow.com/questions/7965437/undefined-reference-to-main-collect2-ld-returned-1-exit-status">Undefined reference to main - collect2: ld returned 1 exit status</a> and <a href="https://stackoverflow.com/questions/1485239/qtcreator-build-returns-collect2-ld-returned-exit-status-1">QtCreator build returns collect2: ld returned exit status 1</a> but these types of cases don't seem to fit.</p>
  
  <p>I am writing a program that will automatically re-sign a message after it's been edited. The signing function takes in some information, hashes it with md5 (I know, but legacy requirements), and then encodes the output with Base64 (which takes a series of bytes via const unsigned char*, and the total size of  the message)</p>
  
  <p>I first tried Crypto++ libray for MD5, and it would provide expansion in the future for other hashes and protocols. After a massive number of undefined reference errors in the linking stage, I tried another md5 implementation I found online. This one gives me only two linking errors, but I think they may be caused by the same reason so I'll go with the second library to save post space.</p>
  
  <p>A snippet of my C++ code for the message signing:</p>
  
  <pre><code>string createMessageSignature(string input)
  {
      //byte digest[ CryptoPP::MD5::DIGESTSIZE ];
  
      //CryptoPP::MD5().CalculateDigest( digest, (byte*) input.c_str(), input.length() );
  
      //cout &lt;&lt; "md5 signature: " &lt;&lt; digest &lt;&lt; endl;
  
      //string encodedDigest = base64_encode(digest, 32);
  
      int size = md5(input).length();
      string stringDigest = md5(input);
  
      const unsigned char* digest = reinterpret_cast&lt;const unsigned char*&gt;(stringDigest.c_str());
  
      cout &lt;&lt; "md5 signature hash: " &lt;&lt; digest &lt;&lt; endl;
  
      string encodedDigest = base64_encode(digest, size);
  
      cout &lt;&lt; "signature base64 encoded: " &lt;&lt; encodedDigest &lt;&lt; endl;
  
      return encodedDigest;
  }
  </code></pre>
  
  <p>The md5 library I'm currently using is here: <a href="http://www.zedwood.com/article/121/cpp-md5-function" rel="nofollow noreferrer">http://www.zedwood.com/article/121/cpp-md5-function</a>  (though I want to move to Crypto++ in the end, or maybe OpenSSL).</p>
  
  <p>Error Messages from Linker (using MinGW on Win7, though also happens on GCC in a linux environment):</p>
  
  <pre><code>C:\Users\j********\Desktop\MessageSigner&gt;C:/MinGW/bin/g++ -o MessageSigner.exe M
  essageSigner.cpp
  C:\Users\J****~1\AppData\Local\Temp\ccLejcEo.o:MessageSigner.cpp:(.text+0xc54):
   undefined reference to `md5(std::string)'
  C:\Users\J****~1\AppData\Local\Temp\ccLejcEo.o:MessageSigner.cpp:(.text+0xc9f):
   undefined reference to `md5(std::string)'
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>Any thoughts? Everything seems defined, and the code compiles. I've never had much experience debugging linker errors. Only compile option I've been using is -o for a file name, '-o MessageSigner.exe'</p>
  
  <p>-Jimmy</p>