crystal 命令失败并显示 ld:找不到 -lgc 的库

crystal command fails with ld: library not found for -lgc

尝试从 https://github.com/askn/crystal-by-example 运行 程序 hello 时,我得到以下输出

$ crystal hello.cr
ld: library not found for -lgc
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/senpo/.cache/crystal/crystal-run-hello.tmp'  -rdynamic  -lpcre -lgc -lpthread /opt/brew/Cellar/crystal-lang/0.24.1_1/src/ext/libcrystal.a -levent -liconv -ldl -L/usr/lib -L/usr/local/lib`

我已经试过了

  1. xcode-select --install
  2. xcode-select --switch /Library/Developer/CommandLineTools
  3. 重新安装XCode

但仍然出现同样的错误。谁能帮助我正确安装 crystal?

运行 它与 run 命令

crystal run hello.cr

或者您可以构建包和 运行 构建代码

crystal build hello.cr
./hello

我在 https://github.com/crystal-lang/crystal/issues/3067 中找到了解决方案。这似乎是一个已知的 crystal 问题。解决方案是将环境变量 LIBRARY_PATH 设置为自制软件安装的库文件夹,在我的例子中是 /opt/brew/lib:

export LIBRARY_PATH=/opt/brew/lib