7

I am working on a C++ project which uses boost asio. Trying to build the libraries that use Asia, I am getting the following error

/usr/local/include/boost/asio/ssl/detail/openssl_types.hpp:19:10: fatal error: 'openssl/conf.h' file not found
#include <openssl/conf.h>

Looking of solutions here & here, I tried

brew install openssl
brew link openssl --force
xcode-select --install

But didn't help.

Doing the following also doesn't seem to work

export C_INCLUDE_PATH=/usr/local/include
export CPLUS_INCLUDE_PATH=/usr/local/include

Boost version I am using is boost_1_63_0. I am on MacOS Sierra with Xcode 8.3.1. I have installed boost using Homebrew

brew install boost

As I understand from other links, Xcode is looking at the wrong place for ssl headers. But how can I resolve this?

I looked into my /usr/local/include & /opt/local/include. 'openssl/ssl.h' is not present in either locations. But doing a brew install openssl says the following

Warning: openssl is a keg-only and another version is linked to opt.
Use `brew install --force` if you want to install this version

Doing a brew install openssl --force says

Warning: openssl-1.0.2k already installed, it's just not linked.

Doing brew link openssl --force also doesn't solve the issue.

Doig a which openssl returns the following:

/usr/local/bin/openssl

Please suggest

Community
  • 1
  • 1
TheWaterProgrammer
  • 7,055
  • 12
  • 70
  • 159

2 Answers2

12

Linked or not, all installed Homebrew packages are reachable via link in /usr/local/opt. Additionally, when you install openssl via Homebrew, Homebrew tells you how to use the openssl libraries and headers.

~ nega@rust 15s
❯ brew install openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2k.el_capitan.bottle.tar.gz
Already downloaded: /Users/nega/Library/Caches/Homebrew/openssl-1.0.2k.el_capitan.bottle.tar.gz
==> Pouring openssl-1.0.2k.el_capitan.bottle.tar.gz
==> Using the sandbox
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include
For pkg-config to find this software you may need to set:
    PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig

==> Summary
  /usr/local/Cellar/openssl/1.0.2k: 1,696 files, 12MB

~ nega@rust 11s
❯ 

You don't need to brew link anything. Just use the directories Homebrew tells you about in the appropriate places in Xcode and CMake.

nega
  • 2,526
  • 20
  • 25
  • well. I had to include & link to the installed location of openssl in my cmake build. thanks for the clarification @nega – TheWaterProgrammer Apr 17 '17 at 17:00
  • @nega - Doesn't work for me, it says : openssl is a keg-only and another version is linked to opt. – dcp May 31 '17 at 02:12
  • @dcp what do you mean it "doesn't work"? maybe if you open a new question and link to it here, i could help out. – nega Jun 01 '17 at 04:49
  • @nega - Thanks for your response and offer to help. In this case, openssl was already installed (maybe as part of the OS?) and I think brew was just telling me it couldn't install it since it would conflict with the installed version. Anyway, the installed version is working ok, so all is well. Thanks. – dcp Jun 09 '17 at 16:08
3

Thanks to @nega for their answer. I'm posting an updated version of the install message for the Apple M1 chip (Arm64) which is too long to leave as a comment on their answer unfortunately!

A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /opt/homebrew/etc/openssl@1.1/certs

and run
  /opt/homebrew/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"

As @nega said, you don't need to brew link anything. I exported the environment variables PATH, LDFLAGS and CPPFLAGS in my bash session as recommended in the message, and then make worked fine for me.

samjewell
  • 1,068
  • 11
  • 20