Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking OpenSSL libraries to a program

Tags:

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?

like image 914
mrduclaw Avatar asked Dec 04 '10 08:12

mrduclaw


People also ask

Where are OpenSSL libraries?

on Fedora 22 32-bit, they are located in /usr/lib, on Ubuntu 15.04 64-bit, the 32-bit OpenSSL libraries are located in /lib/i386-linux-gnu. libcrypto should be in the same directory as libssl.


1 Answers

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

like image 56
mrduclaw Avatar answered Oct 11 '22 04:10

mrduclaw