I am trying to code in C on OS X (El Capitan) and need to use OpenSSL. OS ships with version 0.9.8zh 14 Jan 2016.

I used homebrew to upgrade and install openssl (got version 1.0.2h) but am unable to link it correctly to use it. This is what is did:

brew update

brew install openssl

brew link --force openssl

which gave me error saying

Warning: Refusing to link: openssl.

My path references /usr/local/bin as the first one.

Ran this command: ln -s /usr/local/Cellar/openssl/1.0.2j/include/openssl /usr/local/include/openssl

(found this solution here: Openssl with El Capitan among other places)

got no error output, so I assumed this worked. But..

which openssl gives me this output: /usr/local/bin/openssl

openssl version gives me this output: OpenSSL 0.9.8zh 14 Jan 2016

All I'm trying to do is run some CLI commands/ write some C code edited in plain vi editor, compiled using gcc. I am including openssl in header files using

 #include <openssl/sha.h>
#include <openssl/ripemd.h>

Also, the command I am running on CLI which led me to this path was this (if that helps):

openssl dgst -sha256 -sign ec-priv.pem ex-message.txt >ex-signature.der.

Gives me an error:

EVP_SignFinal:wrong public key type.

Googling led me to understand it's cause of an old OpenSSL version which I need to update.

Any ideas on how to proceed here?

  • Have you entered a new shell after lionking the file but before running whgich? For the C compile we need to see the C compiler and linker command lines
    – mmmmmm
    Oct 3, 2016 at 12:02
  • Thanks @Mark. Opening a new shell and running openssl version showed me the correct version. SO it got linked properly and i was just not seeing the correct version as i was running it all in old shell. I am putting this here as answer as i am not allowed to comment. Couldn't find any other way to respond to you. If you put this as an answer, I will accept it. Oct 3, 2016 at 13:02

2 Answers 2


You'll need to make sure you open a new shell after performing the link. (I updated my medium article you linked for future reference: Openssl with El Capitan).

  • This alters the executabe but doe not chnage the include or link paths
    – mmmmmm
    Oct 20, 2016 at 16:52

From Brew refusing to link openssl on Stack Overflow and Issue 3964, .Net GitHub (I think it was first reported with .Net):

I looked into the other option that was suggested for setting the rpath on the library. I think the following is a better solution that will only effect this specific library.

sudo install_name_tool -add_rpath /usr/local/opt/openssl/lib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/System.Security.Cryptography.Native.dylib

and/or if you have NETCore 1.0.1 installed perform the same command for 1.0.1 as well:

sudo install_name_tool -add_rpath /usr/local/opt/openssl/lib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.1/System.Security.Cryptography.Native.dylib

In effect, rather than telling the operating system to always use the homebrew version of SSL and potentially causing something to break, we're telling dotnet how to find the correct library.

which openssl gives me this output: /usr/local/bin/openssl

openssl version gives me this output: OpenSSL 0.9.8zh 14 Jan 2016

Add an rpath to the openssl executable. OpenSSL's build system does not supply an rpath. At runtime, your new executable links to the old libraries.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .