Search code examples
linuxgccopenssl

Linking OpenSSL libraries to a program


I have built OpenSSL from source (an intentionally old version; built with ./config && make && make test) and would prefer to use what I have built without doing make install to link against my program.

The command that's failing is:

gcc -Wall -Wextra -Werror -static -Lopenssl/openssl-0.9.8k/ -lssl -lcrypto 
-Iopenssl/openssl-0.9.8k/include -o myApp source1.o source2.o common.o`

And I receive a series of errors similar to:

common.c:(.text+0x1ea): undefined reference to `SSL_write'

This makes me think there's something funky with my OpenSSL. If I omit -Lopenssl/openssl-0.9.8k/ from my command, the error changes to being unable to:

/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto

Am I compiling OpenSSL incorrectly? Or how should I best resolve this?


Solution

  • Silly "Linux-isms" strike again! Apparently, I need to change my command such that the -L and -l stuff is at the end like (despite what man gcc seems to indicate):

    gcc -Wall -Wextra -Werror -static -o myApp source1.o source2.o common.o -Lopenssl/openssl-0.9.8k/ -lssl -lcrypto -Iopenssl/openssl-0.9.8k/include