I have OpenSSL installed through the Homebrew package manager. I have found the library and header files I need.

The headers are:


The library files are:


I've tried several gcc commands to try to link the OpenSSL library, including:

gcc md5.c -I/usr/local/Cellar/openssl/1.0.2k/include -lssl
gcc md5.c -I/usr/local/Cellar/openssl/1.0.2k/include -llibssl
gcc md5.c -I/usr/local/Cellar/openssl/1.0.2k/include -llibssl.dylib
gcc md5.c -I/usr/local/Cellar/openssl/1.0.2k/include -llibssl.0.9.8
gcc md5.c -I/usr/local/Cellar/openssl/1.0.2k/include -llibssl.0.9.8.dylib

All of them produce either a "File not found" error or a linker error.

What's the proper way to do this?

  • 1
    Does homebrew put a *.pc package config file for it anywhere? – thrig Feb 22 '17 at 16:48
  • @thrig I found several: /usr/local/Cellar/openssl/1.0.2h_1/lib/pkgconfig/libcrypto.pc /usr/local/Cellar/openssl/1.0.2h_1/lib/pkgconfig/libssl.pc /usr/local/Cellar/openssl/1.0.2h_1/lib/pkgconfig/openssl.pc /usr/local/Cellar/openssl/1.0.2j/lib/pkgconfig/libcrypto.pc /usr/local/Cellar/openssl/1.0.2j/lib/pkgconfig/libssl.pc /usr/local/Cellar/openssl/1.0.2j/lib/pkgconfig/openssl.pc /usr/local/Cellar/openssl/1.0.2k/lib/pkgconfig/libcrypto.pc /usr/local/Cellar/openssl/1.0.2k/lib/pkgconfig/libssl.pc /usr/local/Cellar/openssl/1.0.2k/lib/pkgconfig/op... – Legend of Overfiend Feb 22 '17 at 17:30
  • You'll probably either need to do a brew switch ... to "activate" one of those openssl versions, or with PKG_CONFIG_PATH set to include one of those pkgconfig directories you could do pkg-config --cflags --libs openssl to get the necessary flags for compile. – thrig Feb 22 '17 at 18:02

It looks like you are trying to link against the openssl libraries installed with your os, rather than the homebrew libraries. Try to find where homebrew installed the 1.0.2k libraries.

find /usr/local/Cellar/ -name "libssl.*"

You should find something like /usr/local/Cellar/_path_of some_sort/libssl.a. Try to link against this library rather than the ones in /usr/lib. The /usr/lib libraries are old and not compatible with the header files you are using.

gcc md5.c -I/usr/local/Cellar/openssl/1.0.2k/include -L/usr/local/Cellar/path_of_some_sort/ -lssl -lcrypto -o md5
  • Specifically, the following worked for me: gcc -Wall -g -L/usr/local/Cellar//openssl@1.1/1.1.0g/lib/ -I/usr/local/Cellar//openssl@1.1/1.1.0g/ -lcrypto -o urtorrent urtorrent.o bencode.o metainfo.c filestring.o – Goodword Jan 31 at 21:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.