ld: library not found for -lssl
Asked Answered
A

6

17

I installed crystal with homebrew brew install crystal-lang. I was able to compile and run a "Hello World!" program, but when I try to compile the example http server (with one slight modification) I get an error.

HTTP server:

require "http/server"

port = 3000

server = HTTP::Server.new(port) do |context|
  context.response.content_type = "text/plain"
  context.response.print "Hello world! The time is #{Time.now}"
end

puts "listening on http://localhost:" + port.to_s
puts "listening on http://localhost:#{port}"
server.listen

Error:

$ crystal server.cr                                                                                                                                        ~/sw/crystal/Lied-Today
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with code: 1: `cc -o "/Users/Matt/.cache/crystal/crystal-run-server.tmp" "${@}"  -rdynamic  -lz `command -v pkg-config > /dev/null && pkg-config --libs libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs libcrypto || printf %s '-lcrypto'` -lpcre -lgc -lpthread /usr/local/Cellar/crystal-lang/0.21.1_1/src/ext/libcrystal.a -levent -liconv -ldl -L/usr/lib -L/usr/local/lib`

I've tried the following:

Adding export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/lib" to ~/.zshrc.

and

$ xcode-select --install
$ xcode-select --switch /Library/Developer/CommandLineTools
Avisavitaminosis answered 16/3, 2017 at 20:53 Comment(0)
K
23

I had to add LIBRARY_PATH to fix this.

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
Katonah answered 20/2, 2020 at 4:46 Comment(1)
I had to use export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/opt/openssl/lib/Gram
A
8

I needed to let Xcode finish installing, before running the second xcode-select command.

Avisavitaminosis answered 16/3, 2017 at 21:6 Comment(0)
L
5

Just include the Lib

brew install openssl
echo 'export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/' >> ~/.zshrc
source ~/.zshrc
Lowrance answered 15/5, 2020 at 6:32 Comment(0)
A
2

Adding the package config Juan mentioned worked for me, here are commands to add it so you don't need to specify every time:

echo 'export PATH="/usr/local/opt/llvm@8/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
Automatism answered 4/10, 2019 at 4:48 Comment(0)
A
1

Providing pkgconfig path for openssl library fixed the problem for me:

PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig" crystal <command>
Aster answered 11/9, 2019 at 12:51 Comment(0)
P
0

As of MacOS Monterey, Matias' solution works and it's also in the official documentation now.

brew install openssl
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opt/openssl/lib/pkgconfig
Piefer answered 14/5, 2022 at 10:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.