Home » Errors & Failures » How to solve : undefined reference to `MD5_Init’

How to solve : undefined reference to `MD5_Init’

If you are compiling a c propgram which calculates MD5 using a c program, there are higher chances you will encounter an errors like below,

/tmp/cc1eHvha.o: In function `calculate_file_md5':
md5-calculate.c:(.text+0x7b): undefined reference to `MD5_Init'
md5-calculate.c:(.text+0x9d): undefined reference to `MD5_Update'
md5-calculate.c:(.text+0xe1): undefined reference to `MD5_Final'
collect2: error: ld returned 1 exit status

The MD5 functionality is part of OpenSSL cryptographic library. The OpenSSL crypto library implements a wide range of cryptographic algorithms used in various Internet standards. The services provided by this library are used by the OpenSSL implementations of SSL, TLS and S/MIME, and they have also been used to implement SSH, OpenPGP, and other cryptographic standards. libcrypto consists of a number of sub-libraries that implement the individual algorithms. The functionality includes symmetric encryption, public key cryptography and key agreement, certificate handling, cryptographic hash functions, cryptographic pseudo-random number generator, and various utilities.

Solution : You are missing to link the crypto library ( -lcrypto ) during the command line compilation, hence link the same as,

 $ gcc -o md5-calculate  md5-calculate.c -lcrypto 

You may refer to “C program to calculate md5 of a file and check if it matches with predefined / downloaded md5sum


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment