Ricain
Ricain

Reputation: 706

openssl/ssl.h not found but installed with homebrew

I am working on a C++ project on my Mac running El Capitan and I get this error even after installing openssl with Homebrew:

g++ -Wall -g -std=c++11 -I../libSocket/src -I../libData/src  -c src/fsslhandler.cpp -o obj/fsslhandler.o
In file included from src/fsslhandler.cpp:1:
In file included from src/fsslhandler.h:8:
../libSocket/src/sslsocket.h:6:10: fatal error: 'openssl/ssl.h' file not found
#include <openssl/ssl.h>
         ^
1 error generated.
make: *** [obj/fsslhandler.o] Error 1

After searching for a solution I found one which does not work:

brew link openssl --force

In order to make it work, I have to add the following flags at compilation:

LDFLAGS: -L/usr/local/opt/openssl/lib

CPPFLAGS: -I/usr/local/opt/openssl/include

How to make it work without this flags?

Openssl use to work on El Capitan installed with brew, but I reinstalled OS X and update openssl with homebrew and here I am.

Thank

Upvotes: 24

Views: 35242

Answers (5)

Pankaj Patil
Pankaj Patil

Reputation: 106

If you need to have openssl@3 first in your PATH, run:

echo 'export PATH="$(brew --prefix openssl@3)/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@3 you may need to set:

export LDFLAGS="-L$(brew --prefix openssl@3)/lib"
export CPPFLAGS="-I$(brew --prefix openssl@3)/include"

For pkg-config to find openssl@3 you may need to set:

export PKG_CONFIG_PATH="$(brew --prefix openssl@3)/lib/pkgconfig"

Upvotes: 5

Andromeda
Andromeda

Reputation: 1463

If openssl is installed using brew, go to the

cd /Library/Developer/CommandLineTools/usr/include

and run:

sudo ln -s /opt/homebrew/opt/openssl@3/include/openssl .

This answer describes in detail

Upvotes: 1

Greg Sadetsky
Greg Sadetsky

Reputation: 5092

based on @chouyangv3's answer, and @hannes ach's comment, this worked for me on a M1 chip under macOS 12.7:

export PATH="/opt/homebrew/Cellar/openssl@3/3.0.8/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/Cellar/openssl@3/3.0.8/lib"
export CPPFLAGS="-I/opt/homebrew/Cellar/openssl@3/3.0.8/include"
export PKG_CONFIG_PATH="/opt/homebrew/Cellar/openssl@3/3.0.8/lib/pkgconfig"

Upvotes: 1

chouyangv3
chouyangv3

Reputation: 505

Try put these in your bash or zsh profile.

export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

Upvotes: 23

Ricain
Ricain

Reputation: 706

I found the solution: clang was not looking in the right place.

xcode-select --install

This post resolved this issue: On mac, g++ (clang) fails to search /usr/local/include and /usr/local/lib by default

Upvotes: 10

Related Questions