ld:找不到-lssl的库

时间:2017-03-16 20:53:59

标签: macos crystal-lang

我用自制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

5 个答案:

答案 0 :(得分:10)

我必须添加LIBRARY_PATH来解决此问题。

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

答案 1 :(得分:7)

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

答案 2 :(得分:1)

为openssl库提供pkgconfig路径已解决了我的问题:

var body: some View {

    return Text(String("Red \(Int(currentRed * 255.0))")) // <- Returns Error without cast to String
               .foregroundColor(Color(red: self.currentRed, green: 0.0, blue: 0.0)) // <- Returns same error }

答案 3 :(得分:1)

只需包括库

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

答案 4 :(得分:0)

添加提到的软件包配置Juan对我有用,这是添加它的命令,因此您无需每次都指定:

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