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

Android Android Commands Android Java Applications Application Libraries Bash / Shell Scripts Bluetooth driver Build Frameworks Commands and Packages Core Kernel C Programs Development Environment Setup Documents / Books Errors & Failures File Systems Framebuffer / Display Driver git Go Language Programs Hardware Platforms Home JAVA Programs Kernel & Device Drivers Kernel Booting and Porting Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL NDK / Middleware / HAL Network Driver OS Concepts PHP Procfs Filesystem Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded

Leave a Reply