Mac OSX fatal error: ‘openssl/sha.h’ file not found

By | April 19, 2016

If you have come across this sha.h not found error on a Mac, it is because Apple dropped support for openssl.

Apple deprecated its OpenSSL shared libraries a while back (with OS X 10.7). That’s because OpenSSL doesn’t offer release-to-release binary compatibility, so we can’t update the shared libraries to the latest OpenSSL without breaking all the existing clients.


How to get around this?

> brew install openssl

This is the easiest and quickest way. This will install a folder called openssl into your /usr/local/Cellar folder (where all your other brew downloads reside).

The trick though is to go into your usr/local/includes folder and create a symlink (aka folder shortcut in the windows world) to your Cellar folder.

cd /usr/local/include 
ln -s ../opt/openssl/include/openssl .

ln is to create a link and -s means it is symbolic. Next we are saying what is the destination and the . (dot) indicates to create the link in the current directory.

Now when you compile the code, the warning should disappear because your compiler will search in this directory (one of many standard directories) and find the header file sha.h via the shortcut link.

You should probably run a few other commands as best practise:

brew doctor 
> brew update 
> brew upgrade

Inspired by:

Category: OSX

8 thoughts on “Mac OSX fatal error: ‘openssl/sha.h’ file not found

  1. Konstantin

    I was able to include all the necessary files.
    But when I compile I get this error (socketserver is the filename):
    Undefined symbols for architecture x86_64:
    “_SHA1_Final”, referenced from:
    _main in socketserver-02e8fa.o
    “_SHA1_Init”, referenced from:
    _main in socketserver-02e8fa.o
    “_SHA1_Update”, referenced from:
    _main in socketserver-02e8fa.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    Any suggestions?

  2. Hash

    Thank you, after hours of hitting my head to the wall, finally this thread solved the error that I was getting.

  3. s

    Thank you for the concise explanation, other answers online were confusing (barely explained the commands you’re asked to copy and paste) and did not work for me.

  4. sultan

    hi when I try this I get this error
    sultanalamri@alAiralsbsultan ~ % cd /usr/local/include
    cd: no such file or directory: /usr/local/include


Leave a Reply

Your email address will not be published. Required fields are marked *