Search code examples
macoscrystal-lang

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


When trying to run the program hello from https://github.com/askn/crystal-by-example, I get the following output

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

I've already tried to

  1. xcode-select --install
  2. xcode-select --switch /Library/Developer/CommandLineTools
  3. Reinstall XCode

but still get the same error. Can anyone help me get my crystal installation right?


Solution

  • I've found a solution in https://github.com/crystal-lang/crystal/issues/3067. It seems to be a known crystal issue. The solution is to set the environment variable LIBRARY_PATH to the library folder of the homebrew installation, in my case /opt/brew/lib:

    export LIBRARY_PATH=/opt/brew/lib