Linking OpenSSL libraries to a program Linking OpenSSL libraries to a program linux linux

Linking OpenSSL libraries to a program


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


Why don't you want to use make install? It can copy generated binaries in the directory you want if you previously passed it to ./configure --prefix $HOME/target_library_install_directory

If you used this trick with every library you build and install, you could then add the target directory to the LIBRARY_PATH environment variable and avoid using -L option.


If you use Autotools, or you are building an Autools project like cURL, then you should be able to use pkg-config. The idea is the Autotools package will read OpenSSL's package configuration and things will "just work" for you.

The OpenSSL package configuration library name is openssl.

You would use it like so in a makefile based project.

%.o: %.c        $(CC) -o $@ -c `pkg-config --cflags openssl` $^target: foo.o bar.o baz.o        $(CC) -o $@ `pkg-config --libs openssl` $^

Also see How to use pkg-config in Make and How to use pkg-config to link a library statically.