Compilation on OpenBSD

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:

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/ :

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

Thanks for your help.

Hello,

Crystal uses pkg-config to detect libraries.

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

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

OpenSSL 4.0 support was added very recently:

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

A similar BSD-related issue was reported a long time ago.

Also, the free AI tool DeepWiki may help you analyze this problem.