# Compilation on OpenBSD

**URL:** <https://forum.crystal-lang.org/t/compilation-on-openbsd/9019>\
**Category:** Help & Support\
**Created:** [June 20, 2026, 5:01pm UTC](https://forum.crystal-lang.org/t/compilation-on-openbsd/9019 "2026-06-20T17:01:48Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![karchnu](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@karchnu](https://forum.crystal-lang.org/u/karchnu)\
**Post date:** [June 20, 2026, 5:01pm UTC](https://forum.crystal-lang.org/t/compilation-on-openbsd/9019/1 "2026-06-20T17:01:48Z")

</div>

Hello,

I’ve tried to compile my project on Linux and it works great, however I have problems on OpenBSD.

The default crypto library is LibreSSL and I had to use `pkg_add openssl` to install OpenSSL. Fine.

Now, I try to compile my project and it doesn’t work, I guess because the OpenSSL library isn’t in the usual folder, headers are in `/usr/local/include/eopenssl40/` and the library is in`/usr/local/lib/eopenssl40`.

But I can’t get it to work even when using `shards build myprogramm -- --linker-flags='-L /usr/local/lib/eopenssl40 -lssl -lcrypto'`. I still get this error:

```bash
test$ shards build authd --link-flags='-I/usr/local/include/eopenssl40/ -L/usr/local/lib/eopenssl40/ -lssl -lcrypto'         
Dependencies are satisfied
Building: authd
Error target authd failed to compile:
Showing last frame. Use --error-trace for full trace.

There was a problem expanding macro 'macro_10576938180752'

Code in lib/openssl_ext/src/openssl_ext/bio/bio.cr:10:5

 10 | {% if OpenSSL::BIO.has_method?(:ktls_recv?) %}
      ^
Called macro defined in lib/openssl_ext/src/openssl_ext/bio/bio.cr:10:5

 10 | {% if OpenSSL::BIO.has_method?(:ktls_recv?) %}

Which expanded to:

   1 | 
 > 2 | Box(IO).unbox(LibCrypto.BIO_get_data(bio))
                                     ^-----------
Error: undefined fun 'BIO_get_data' for LibCrypto

```

The problem comes from the `openssl_ext` library (used by `crystal-community/jwt`).

I really don’t know what to do at this point. I can write anything in the `--link-flags=` parameter, it changes absolutely nothing. But I know that the library is in `/usr/local/lib/eopenssl40/` :

```auto
test$ nm -g /usr/local/lib/eopenssl40/libcrypto.so.45.0 | grep BIO_get_data                                                                                                                                                                   
00251b10 T BIO_get_data

```

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![kojix2](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/kojix2/32/1583_2.png) [@kojix2](https://forum.crystal-lang.org/u/kojix2)\
**Post date:** [June 21, 2026, 12:41am UTC](https://forum.crystal-lang.org/t/compilation-on-openbsd/9019/2 "2026-06-21T00:41:05Z")

</div>

Hello,

Crystal uses `pkg-config` to detect libraries.

Is `pkg-config` installed on your system, and can it detect your SSL library?

```sh
pkg-config --variable=includedir libssl
pkg-config --modversion libssl
pkg-config --libs libssl

```

However, you also set `--link-flags`, so this may not be the real cause.

The OpenSSL detection logic is around [here](https://github.com/crystal-lang/crystal/blob/master/src/openssl/lib_ssl.cr#L7C1-L58C10)

OpenSSL 4.0 support was added very recently:

> <https://github.com/crystal-lang/crystal/commit/a9cef1ff33d1ae7cfaa7bf78d02a4d44bdf2983c>
>
> \[OpenSSL 4.0.0\] is out and this brings compatibility with the new release, follo…wing the \[migration guide\].
> Still waiting for package availability in order to install \`openssl\` in CI workflow.
> Alpine Linux seems to be in no hurry to add support for OpenSSL 4 (they don't even have 3.6).
> 
> \[OpenSSL 4.0.0\]: https://github.com/openssl/openssl/releases/tag/openssl-4.0.0
> \[migration guide\]: https://docs.openssl.org/4.0/man7/ossl-guide-migration/#openssl-40
> 
> Co-authored-by: Julien Portalier \<julien@portalier.com\>

This part is quite complex, so there may be some reason why detection does not work in your environment.

A similar BSD-related [issue](https://github.com/crystal-lang/crystal/issues/7244) was reported a long time ago.

Also, the free AI tool [DeepWiki](https://deepwiki.com/crystal-lang/crystal) may help you analyze this problem.

---

<div class="post-metadata">

**Author:** ![karchnu](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@karchnu](https://forum.crystal-lang.org/u/karchnu)\
**Post date:** [June 21, 2026, 9:35am UTC](https://forum.crystal-lang.org/t/compilation-on-openbsd/9019/3 "2026-06-21T09:35:05Z")

</div>

Thanks for your answer.

I tried OpenSSL 3.5, too. It doesn’t change anything.

I have `pkg-config` installed and it works:

```bash
test$ pkg-config --variable=includedir libssl              
/usr/include
test$ pkg-config --modversion libssl                       
2.0.0
test$ pkg-config --libs libssl                
-lssl

```

I don’t even get _what_ is wrong. The error is `Error: undefined fun 'BIO_get_data' for LibCrypto` but this function does exist in `LibCrypto` and it isn’t conditioned by the detection of any library or environment. The function is just there. The error doesn’t seem to come from the linker at all.

The crystal compiler version:

```bash
test$ crystal version
Crystal 1.17.1 [19be240d1] (2025-07-22)

The compiler was not built in release mode.

LLVM: 19.1.7
Default target: x86_64-unknown-openbsd7.9

```

I don’t think it should be a problem, but since I’m out of ideas, idk.

EDIT: the library detection seems to fail:

```bash
test$ crystal eval 'require "openssl"; puts LibSSL::OPENSSL_VERSION'
0.0.0

```

I don’t know if it is of some any significance in my specific case, but it still seems wrong.

---

<div class="post-metadata">

**Author:** ![ysbaddaden](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/ysbaddaden/32/2252_2.png) [@ysbaddaden](https://forum.crystal-lang.org/u/ysbaddaden)\
**Post date:** [June 21, 2026, 10:38am UTC](https://forum.crystal-lang.org/t/compilation-on-openbsd/9019/4 "2026-06-21T10:38:19Z")

</div>

You have libressl installed and found, not openssl, ~~and a very old and unsupported version at that. I think we only support 3.x and you probably should consider 4.x~~

---

<div class="post-metadata">

**Author:** ![ysbaddaden](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/ysbaddaden/32/2252_2.png) [@ysbaddaden](https://forum.crystal-lang.org/u/ysbaddaden)\
**Post date:** [June 21, 2026, 10:39am UTC](https://forum.crystal-lang.org/t/compilation-on-openbsd/9019/5 "2026-06-21T10:39:55Z")

</div>

That, or the pkg-config lies for libressl (that’s possible) and we should upgrade to a version detector based on the variables in the C headers, which is the only safe mean to detect the correct openssl/libressl version.

---

<div class="post-metadata">

**Author:** ![kojix2](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/kojix2/32/1583_2.png) [@kojix2](https://forum.crystal-lang.org/u/kojix2)\
**Post date:** [June 21, 2026, 12:13pm UTC](https://forum.crystal-lang.org/t/compilation-on-openbsd/9019/6 "2026-06-21T12:13:03Z")

</div>

pkg-config might not be finding the `.pc` file.  
If the `.pc` file is in a non‑standard directory, setting `PKG_CONFIG_PATH` may help.

---

<div class="post-metadata">

**Author:** ![ysbaddaden](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/ysbaddaden/32/2252_2.png) [@ysbaddaden](https://forum.crystal-lang.org/u/ysbaddaden)\
**Post date:** [June 21, 2026, 12:15pm UTC](https://forum.crystal-lang.org/t/compilation-on-openbsd/9019/7 "2026-06-21T12:15:20Z")

</div>

Confirmed: I booted my OpenBSD 7.6 VM and `/usr/lib/pkg-config/libssl.pc` file is stuck to report the version as 2.0.0, despite having libressl 4.0.0 installed.

Looking at `/usr/include/openssl/opensslv.h` it reflects the `OPENSSL_VERSION_NUMBER` of 0x20000000L while `LIBRESSL_VERSION_NUMBER` is 0x4000000fL 🤷

---

<div class="post-metadata">

**Author:** ![ysbaddaden](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/ysbaddaden/32/2252_2.png) [@ysbaddaden](https://forum.crystal-lang.org/u/ysbaddaden)\
**Post date:** [June 21, 2026, 12:27pm UTC](https://forum.crystal-lang.org/t/compilation-on-openbsd/9019/9 "2026-06-21T12:27:52Z")

</div>

@karchnu If you really want OpenSSL, you must tweak `PKG_CONFIG_DIR` so its `libssl.pc` and `libcrypto.pc` files can be found. We do support LibreSSL however, and you should have nothing to do.

On OpenBSD 7.6, I can run the `spec/std/openssl` specs from Crystal `master` branch with the system LibreSSL 4.0.0 without configuration issues (despite the wrong version information reported by `libssl.pc` which means we sadly can’t use new features).

Upgraded to OpenBSD 7.8 and no issues with LibreSSL 4.2.0 either.

---

<div class="post-metadata">

**Author:** ![karchnu](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@karchnu](https://forum.crystal-lang.org/u/karchnu)\
**Post date:** [June 21, 2026, 9:06pm UTC](https://forum.crystal-lang.org/t/compilation-on-openbsd/9019/10 "2026-06-21T21:06:53Z")

</div>

Well, I’m on a fresh install of OpenBSD 7.9. Why isn’t it _just working_ if LibreSSL is supported? In order to _make it work_ with LibreSSL, should I create a `pc` file with the real version of the library?

Both LibreSSL and OpenSSL are fine by me. I just want [spider-gazelle/openssl\_ext](https://github.com/spider-gazelle/openssl_ext/) to work.

Anyway, I installed OpenSSL and copied the version of `libssl.pc` and `libcrypto.pc` found in the package (they didn’t have these names exactly, so it couldn’t work out-the-box) and played with `PKG_CONFIG_PATH` and it worked. Thanks!

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [June 22, 2026, 7:12am UTC](https://forum.crystal-lang.org/t/compilation-on-openbsd/9019/11 "2026-06-22T07:12:04Z")

</div>

@ysbaddaden compatibility statements are about _standard library_ support for LibreSSL.

But the error is coming from 3rd-party code in [GitHub - spider-gazelle/openssl\_ext: Crystal bindings for OpenSSL RSA · GitHub](https://github.com/spider-gazelle/openssl_ext/), which does not look like it explicitly supports LibreSSL. Also, not sure which versions of OpenSSL are supported.  
Would be nice to mention supported versions somewhere. Ping @stakach

Another issue seems to be that you’re using an older version of Crystal’s standard library. Please always report which version of Crystal you’re using so people who want to help can give you the right advice.  
`LibCrypt.BIO_get_data` should always be defined since Crystal 1.19. Since it’s missing, it means pre-1.19 stdlib detected a libcrypto version of OpenSSL \< 1.1.0 or LibreSSL \< 2.7.0 where this symbol doesn’t exist.  
Using an older stdlib is not necessarily a problem. But upgrading to latest might even fix this problem (although there might be further issues).

---

<div class="post-metadata">

**Author:** ![stakach](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/stakach/32/58_2.png) [@stakach](https://forum.crystal-lang.org/u/stakach)\
**Post date:** [June 22, 2026, 12:22pm UTC](https://forum.crystal-lang.org/t/compilation-on-openbsd/9019/12 "2026-06-22T12:22:05Z")

</div>

It’s tested against linux, mac and windows. Not really sure what versions are supported TBH

Happy to accept pull requests or increase CI coverage to other OS’s

---

<div class="post-metadata">

**Author:** ![ysbaddaden](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/ysbaddaden/32/2252_2.png) [@ysbaddaden](https://forum.crystal-lang.org/u/ysbaddaden)\
**Post date:** [June 22, 2026, 1:20pm UTC](https://forum.crystal-lang.org/t/compilation-on-openbsd/9019/13 "2026-06-22T13:20:19Z")

</div>

@stakach Did you test with LibreSSL? That’s the issue, here.
