ld: 找不到-lssl库

16

我使用homebrew安装了crystal brew install crystal-lang。我能够编译并运行“Hello World!”程序,但是当我尝试编译示例http服务器(稍作修改)时,出现了错误。

HTTP服务器代码:

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

错误:

$ 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`

我已经尝试了以下方法:

export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/lib"添加到~/.zshrc文件中。

$ xcode-select --install
$ xcode-select --switch /Library/Developer/CommandLineTools
6个回答

20

我不得不添加LIBRARY_PATH来解决这个问题。

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

2
我必须使用以下命令:export LIBRARY_PATH=$LIBRARY_PATH:/opt/homebrew/opt/openssl/lib/ - Alexandre Campos
这对我也起作用 - sprckt

8

在运行第二个xcode-select命令之前,我需要让Xcode完成安装。


5

只需包含这个库即可

brew install openssl
echo 'export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/' >> ~/.zshrc
source ~/.zshrc

2

我遇到了Juan提到的问题,添加他提到的软件包配置对我有用。以下是添加它的命令,这样您就不需要每次都指定:

echo 'export PATH="/usr/local/opt/llvm@8/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

1
提供openssl库的pkgconfig路径解决了我的问题。
PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig" crystal <command>

0

从MacOS Monterey开始,Matias的解决方案可以使用,并且现在也在官方文档中了。

brew install openssl
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/opt/openssl/lib/pkgconfig

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接