openssl/ssl.h not found but installed with homebrew
Asked Answered
F

5

23

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

Frasch answered 9/12, 2015 at 12:36 Comment(1)
OpenSSL now seems to install at /opt/homebrew/opt/openssl/Nunhood
F
10

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

Frasch answered 9/12, 2015 at 13:13 Comment(1)
When I run this command Mac OS tells me I already have command line tools installed.Pericline
H
22

Try put these in your bash or zsh profile.

export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
export PKG_CONFIG_PATH="/usr/local/opt/[email protected]/lib/pkgconfig"
Haeckel answered 17/10, 2020 at 9:54 Comment(4)
Unfortunately it doesn't work. All on Apple Silicon M1 and changed path /opt/homebrew/opt/openssl@3/Adoration
@hannesach did you found solution ?Sharpnosed
@Sharpnosed On my side all is working now. But I even can't remember exact problemAdoration
try: brew link openssl --forceNingsia
F
10

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

Frasch answered 9/12, 2015 at 13:13 Comment(1)
When I run this command Mac OS tells me I already have command line tools installed.Pericline
K
2

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"
Kieffer answered 28/7, 2022 at 6:10 Comment(0)
B
1

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"
Babin answered 3/1 at 5:8 Comment(0)
S
0

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

Stacee answered 3/6 at 16:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.