crystal-lang 学习二 macos openssl 问题

因为我的openssl 是使用brew 安装的,按照一般的解决方法是如下配置

注意我的是按照brew 安装的版本的提示

配置

export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"

但是依然还是提示

Error: execution of command failed with code: 1: `cc "${@}" -o /Users/dalong/.cache/crystal/crystal-run-main.tmp  -rdynamic -L/usr/local/Cellar/crystal/0.35.1/embedded/lib -L/usr/lib -L/usr/local/lib -lz `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto'` -lpcre -lgc -lpthread /usr/local/Cellar/crystal/0.35.1/src/ext/libcrystal.a -L/usr/local/Cellar/libevent/2.1.11_1/lib -levent -liconv -ldl

解决方法

运行时指定连接的lib
参考命令

 
crystal build src/main.cr --link-flags -L/usr/local/opt/openssl@1.1/lib

shards build 说明

同样也是添加链接

shards build  --link-flags -L/usr/local/opt/openssl@1.1/lib

参考资料

https://gitter.im/crystal-lang/crystal?at=5d8df36feb1eff63d63302d4 
https://www.crstin.com/crystal-openssl/ 
https://github.com/crystal-lang/crystal/issues/6875 
https://github.com/rongfengliang/crystal-shards-macos-learning

原文地址:https://www.cnblogs.com/rongfengliang/p/13227236.html