Sunday, September 18, 2011

Compiling Open SSL programs in Eclipse

If you attempt to compile an SSL related project on Eclipse , you are most likely going to get any of the following errors:

undefined reference to `ERR_load_crypto_strings'
undefined reference to `PEM_read_PrivateKey'
undefined reference to `ERR_print_errors_fp'
undefined reference to `EVP_sha1'
undefined reference to `EVP_DigestInit'
undefined reference to `EVP_DigestUpdate'
undefined reference to `EVP_SignFinal'
undefined reference to `ERR_print_errors_fp'
undefined reference to `EVP_PKEY_free'
undefined reference to `PEM_read_X509'
undefined reference to `ERR_print_errors_fp'
undefined reference to `X509_get_pubkey'
undefined reference to `ERR_print_errors_fp'
undefined reference to `EVP_sha1'
undefined reference to `EVP_DigestInit'
undefined reference to `EVP_DigestUpdate'
undefined reference to `EVP_VerifyFinal'
undefined reference to `EVP_PKEY_free'
undefined reference to `ERR_print_errors_fp'


Although your project is configured to include all the libraries that are in the /usr/include path, its still not configured to link against those libraries when generating the binary file for your project. We need to tell the linker that our project is using the openssl libraries.

Solution:

  1. Go to Project > Properties
  2. Navigate to C/C++ Build > Settings
  3. Go to GCC C Linker  > Miscellaneous settings
  4. Add the following in the Linker flags : -lcrypto -lssl
 

2 comments:

  1. I had been struggling with OpenSSL compilation since two weeks! Your solution was just perfect! I was trying on Eclipse and that troubled me quite a lot. I shifted over to Netbeans and Voila! It worked perfectly!

    ReplyDelete