How to link OpenSSL library in macOS using gcc?
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
Related videos on Youtube
Legend of Overfiend
Updated on September 18, 2022Comments
-
Legend of Overfiend over 1 year
I have OpenSSL installed through the Homebrew package manager. I have found the library and header files I need.
The headers are:
/usr/local/Cellar/openssl/1.0.2h_1/include/openssl /usr/local/Cellar/openssl/1.0.2j/include/openssl /usr/local/Cellar/openssl/1.0.2k/include/openssl
The library files are:
/usr/lib/libssl.0.9.7.dylib /usr/lib/libssl.0.9.8.dylib /usr/lib/libssl.dylib
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?
-
Legend of Overfiend about 7 years@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...
-
-
Goodword over 5 yearsSpecifically, the following worked for me:
gcc -Wall -g -L/usr/local/Cellar//[email protected]/1.1.0g/lib/ -I/usr/local/Cellar//[email protected]/1.1.0g/ -lcrypto -o urtorrent urtorrent.o bencode.o metainfo.c filestring.o