Problem with linking the `ssl` lib on macos

Hi,

I’m trying to use the ocaml-ssl lib (GitHub - savonet/ocaml-ssl: OCaml SSL bindings.) in a project on macos.
I installed it with opam install ssl (no problem during installation).

However, I doesn’t build.

Minimal .ml file:

let () = 
Ssl.init();
print_endline "Hello, World!"

Dune file:

(executable
 (public_name test2)
 (name main)
 (libraries test2 ssl))

I get this error:

File "bin/dune", line 3, characters 7-11:
3 |  (name main)
           ^^^^
ld: warning: directory not found for option '-L/opt/homebrew/Cellar/openssl@3/3.1.0/lib'
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
File "caml_startup", line 1:
Error: Error during linking (exit code 1)

I seem to understand that the compiler can’t find the open-ssl directory, but the path in the error message is the right one and has a bunch of files that look legit inside.

Does anyone know how to make it compile, and can you explain what is failing here please?

It’s possible your libraries are out of date. Did you make sure to opam update && opam upgrade?

I should have though of that, sorry.
I just updated everthing and it fixed the problem. I only had a few libs out of date, and none of them were ssl, but I guess it depended on one of them because that did the trick.

Thank you for your help!

1 Like

On MacOS I used to have to run opam reinstall ssl after I had installed everything already (including ssl!). And only then would it work.
I’ve long switched to the tls library but I’d bet that’s the issue you ran into.

Yes, on macOS the installation location of OpenSSL keeps changing. So when you install ssl it remembers to add -L/opt/homebrew/Cellar/openssl@3/3.1.0/lib to the flags. If you upgrade openssl using brew to say 3.1.1 it will live in a new folder, presumably /opt/homebrew/Cellar/openssl@3/3.1.1/lib and delete the older one, thus when OCaml is building your library, L/opt/homebrew/Cellar/openssl@3/3.1.0/lib does not point to a place where the OpenSSL code is located.