Search code examples
macoscmakeopensslhomebrewmacos-sierra

Can't use openssl on macOS-Sierra


I want to get openssl running with CLion (CMake) on my Mac.

Installed openssl with homebrew

brew install openssl

But still CLion is unable to find openssl. In the past it was possible to use

brew link openssl

but it seems that today this is refused by homebrew.

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

Then I used following cmake options in CLion (CMakeLists.txt)

set(I "/usr/local/opt/openssl/include")
set(L "/usr/local/opt/openssl/lib")
include_directories(${I})

But still I get:

Undefined symbols for architecture x86_64:
  "_EVP_DigestSignFinal", referenced from:
Undefined symbols for architecture x86_64:
  "_EVP_DigestSignFinal", referenced from:
      OpenSSL::signMsg(Buffer, Buffer, SignOptions) in libMyLib.a(ssl_state.cpp.o)
      OpenSSL::signMsg(Buffer, Buffer, SignOptions) in libMyLib.a(ssl_state.cpp.o)

Nearly everything I could find to this thematic was about older versions of macOS, but Apple has removed development-headers from openssl 0.9.8, so many guides does not work anymore.


Solution

  • This seems to be an issue with linking. I'm using Macports instead of Homebrew, but also on MacOS Sierra.

    Since I can't see your code and you didn't provide a minimum working example, I used: https://github.com/Andersbakken/openssl-examples.git

    Similar to you, I added the following lines to CMakeLists.txt

    set(I "/opt/local/include")
    set(L "/opt/local/lib")
    include_directories(${I})
    

    and it works just fine for me:

    cmake .
    make
    

    Have you verified, that the necessary files are actually available under the paths, you put in your CMakeLists.txt?

    Have you tried:

    brew info openssl