Using the OpenSSL library with macOS Sierra

Timothy Ko
Oct 10, 2017 · 2 min read

Working with C++ libraries on a Mac can be a pain and OpenSSL, a very popular one that’s used in many other libraries, led me scrambling around the web and going through different StackOverflow posts, Github issues, and blog posts/forums trying to figure out a way to do it without reinstalling everything.

Usually, you would just install OpenSSL with Homebrew….

$ brew install openssl

And then link it…

$ brew link --force openssl
Warning: Refusing to link: openssl
Linking keg-only openssl means you may end up linking against the insecure,
deprecated system OpenSSL while using the headers from Homebrew's openssl.
Instead, pass the full include/library paths to your compiler e.g.:
-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib

But don’t worry! There’s a fix. Homebrew installs OpenSSL but doesn’t link it to /usr/local/include, where the compiler looks into during #include< …> Thus, you must manually link it instead:

$ ln -s /usr/local/opt/openssl/include/openssl /usr/local/include

You also might want to link:

$ ln -s /usr/local/Cellar/openssl/[version]/include/openssl /usr/bin/openssl
$ ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/

An example of [version] is 1.0.2j. And just in case, check whether you compiler looks into /usr/local/include. For clang, it is:

clang -x c -v -E /dev/null

And it should output this if clang searches through /usr/local/include

#include <...> search starts here:

And you should be able to start using OpenSSL! This fix also doesn’t just work with your C++ project but any project(e.g. Ruby project) you are building that uses OpenSSL.

And just a reminder — remember to add -lssl and -lcrypto flags for your compiler.

I hope this guide helped solve a headache of yours! I’m pretty new at this and I’d like to get better — any response is welcome :)

Check out my other posts and tutorials!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store