# Problem with linking the \`ssl\` lib on macos

**URL:** https://discuss.ocaml.org/t/problem-with-linking-the-ssl-lib-on-macos/12988
**Category:** Learning
**Tags:** build, dune
**Created:** [September 8, 2023, 12:37pm UTC](https://discuss.ocaml.org/t/problem-with-linking-the-ssl-lib-on-macos/12988 "2023-09-08T12:37:05Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![lily\_t](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lily_t/32/4684_2.png) [@lily\_t](https://discuss.ocaml.org/u/lily_t)
#### Post date: [September 8, 2023, 12:37pm UTC](https://discuss.ocaml.org/t/problem-with-linking-the-ssl-lib-on-macos/12988/1 "2023-09-08T12:37:05Z")

</div>

Hi,

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

However, I doesn’t build.

Minimal `.ml` file:

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

```

Dune file:

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

```

I get this error:

```auto
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?

---

<div class="post-metadata">

### Author: ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)
#### Post date: [September 8, 2023, 6:34pm UTC](https://discuss.ocaml.org/t/problem-with-linking-the-ssl-lib-on-macos/12988/2 "2023-09-08T18:34:23Z")

</div>

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

---

<div class="post-metadata">

### Author: ![lily\_t](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lily_t/32/4684_2.png) [@lily\_t](https://discuss.ocaml.org/u/lily_t)
#### Post date: [September 9, 2023, 6:22am UTC](https://discuss.ocaml.org/t/problem-with-linking-the-ssl-lib-on-macos/12988/3 "2023-09-09T06:22:25Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![asemio\_sgrondin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/asemio_sgrondin/32/2247_2.png) [@asemio\_sgrondin](https://discuss.ocaml.org/u/asemio_sgrondin)
#### Post date: [September 10, 2023, 3:27pm UTC](https://discuss.ocaml.org/t/problem-with-linking-the-ssl-lib-on-macos/12988/4 "2023-09-10T15:27:44Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Leonidas](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/leonidas/32/4039_2.png) [@Leonidas](https://discuss.ocaml.org/u/Leonidas)
#### Post date: [September 11, 2023, 10:57am UTC](https://discuss.ocaml.org/t/problem-with-linking-the-ssl-lib-on-macos/12988/5 "2023-09-11T10:57:35Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Moe](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@Moe](https://discuss.ocaml.org/u/Moe)
#### Post date: [September 7, 2024, 1:24pm UTC](https://discuss.ocaml.org/t/problem-with-linking-the-ssl-lib-on-macos/12988/6 "2024-09-07T13:24:57Z")

</div>

I know this is old, but solved my issue! Thanks 🙂

---

<div class="post-metadata">

### Author: ![jonsterling](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jonsterling/32/4430_2.png) [@jonsterling](https://discuss.ocaml.org/u/jonsterling)
#### Post date: [September 17, 2024, 10:26am UTC](https://discuss.ocaml.org/t/problem-with-linking-the-ssl-lib-on-macos/12988/7 "2024-09-17T10:26:55Z")

</div>

Same! This is a lifesaver for Mac users.
