openssl/ssl.h not found but installed with homebrew

Ricain picture Ricain · Dec 9, 2015 · Viewed 17.4k times · Source

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

Answer

Ricain picture Ricain · Dec 9, 2015

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