I’m trying to connect a PostgreSQL database to my Kemal app but when I try to run crystal run src/app.cr
I get the following error message
Undefined symbols for architecture arm64:
"_EVP_MD_size", referenced from:
_*OpenSSL::Digest#digest_size:Int32 in O-penS-S-L-5858D-igest.o
_*Digest::MD5@OpenSSL::Digest#digest_size:Int32 in D-igest5858M-D-5.o
"_SSL_get_peer_certificate", referenced from:
_*OpenSSL::SSL::Socket::Client@OpenSSL::SSL::Socket#peer_certificate:(OpenSSL::X509::Certificate | Nil) in O-penS-S-L-5858S-S-L-5858S-ocket5858C-lient.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I installed Crystal with brew install crystal
and then I ran brew install openssl
.
I have no idea what to do to fix this and it does not really seem to be a solution found on Google (at least I have not been able to find any).
# crystal -v
Crystal 1.7.3 (2023-03-07)
LLVM: 14.0.6
Default target: aarch64-apple-darwin22.2.0
# crystal env
CRYSTAL_CACHE_DIR=$HOME/.cache/crystal
CRYSTAL_PATH=lib:/opt/homebrew/Cellar/crystal/1.7.3/libexec/../share/crystal/src
CRYSTAL_VERSION=1.7.3
CRYSTAL_LIBRARY_PATH=/opt/homebrew/Cellar/crystal/1.7.3/libexec/../../../../lib
CRYSTAL_OPTS=''
# simplified app.cr
require "db"
require "pg"
require "kemal"
DB.open "postgres://postgres:postgres@127.0.0.1:5432/mailbox_locator" do |db|
db.exec <<-SQL
CREATE TABLE IF NOT EXISTS mailboxes (
...
);
SQL
end
get "/" do
# ...
render "src/views/index.ecr"
end
Kemal.run
I think you just need openssl@1.1
.
$ brew install openssl@1.1
==> Downloading https://formulae.brew.sh/api/formula.jws.json
######################################################################## 100.0%
Warning: openssl@1.1 1.1.1t is already installed and up-to-date.
To reinstall 1.1.1t, run:
brew reinstall openssl@1.1
looks like I already have it but I know I have openssl@3
too because I did run brew install openssl@3
the other day and I have export PATH="/opt/homebrew/opt/openssl@3/bin:$PATH"
in my .zshrc
file.
Try export PKG_CONFIG_PATH="${PKG_CONFIG_PATH:+$PKG_CONFIG_PATH:}/opt/homebrew/opt/openssl@1.1/lib/pkgconfig
this part tho. To ensure pkg-config is able to find openssl@1.1
libs.
$ export PKG_CONFIG_PATH="${PKG_CONFIG_PATH:+$PKG_CONFIG_PATH:}/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"
$ crystal run src/app.cr
resulted in the same error
What about export CRYSTAL_LIBRARY_PATH=/opt/homebrew/lib:/usr/lib
?
(Basically just suggesting things from that SO post as it seems to be basically what you’re running into)
Same error. I did see this post on SO earlier and I already tried all their suggestions as it was basically the only thing I could find where this error was mentioned.
1 Like
Hmm well dang. I know this error usually relates to pkg-config/the linker not being able to find the proper libs. Unfortunately I don’t have an M1 mac to help test. My hunch is that it still has something to do with CRYSTAL_LIBRARY_PATH
and/or PKG_CONFIG_PATH
and needing to get them to find the right thing. But maybe someone who actually has an M1 will have a better idea.
Really appreciate your help 
I did try to setup Jekyll the other day to run kemalcr.com locally and I got a lot of openssl.h is missing
error. I found this answer ruby - Can't install Jekyll - "fatal error: 'openssl/ssl.h' file not found" - Stack Overflow and ran some of the commands (it did not work btw
) - now I’m wondering if any of these commands could have changed something on my machine that now results in the error I’m facing now? 
Maybe remove all versions except 1.1? Theroetically the brew package should already be setting up the library path right?