I am trying to understand the cause of a linking error. This example is specific, but the cause is probably a general principle I don't understand.
I wanted to build the minimal example from this post. Ubuntu 14.05.5. I did:
$ apt-get install libssl-dev
$ opensll version
OpenSSL 1.0.1f 6 Jan 2014
$ echo $LD_LIBRARY_PATH
/usr/local:
$ gcc -I/usr/include/openssl -o test md5.c -L/usr/lib/x86_64-linux-gnu -lssl
/tmp/ccUSgfgs.o: In function `main':
md5.c:(.text+0x26): undefined reference to `MD5_Init'
md5.c:(.text+0x68): undefined reference to `MD5_Update'
md5.c:(.text+0xab): undefined reference to `MD5_Final'
collect2: error: ld returned 1 exit status
Which throws a common linking error. It can't find the definitions to those symbols. Through random attempts, I found this builds:
$ gcc -I/usr/include/openssl -o test md5.c -L/usr/lib/x86_64-linux-gnu -lcrypto
The only difference is '-l crypto' instead of '-l ssl'
Why does one build and the other not?