Building Crystal language from source on FreeBSD

Having trouble building Crystal from source code. Following the instructions to make (Have to use gmake), I get the following error in build.

Using /usr/local/bin/llvm-config17 [version=17.0.6]
CRYSTAL_CONFIG_BUILD_COMMIT="85f3cc551" CRYSTAL_CONFIG_PATH='$ORIGIN/../share/crystal/src' SOURCE_DATE_EPOCH="1740594523"  CRYSTAL_CONFIG_LIBRARY_PATH='$ORIGIN/../lib/crystal' ./bin/crystal build -D strict_multi_assign -D preview_overload_order -Dwithout_interpreter  -o .build/crystal src/compiler/crystal.cr -D without_openssl -D without_zlib -D use_pcre2
ld: error: unable to find library -lgc-threaded (this usually means you need to install the development package for libgc-threaded)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with exit status 1: cc "${@}" -o /home/jsherman/.cache/crystal/home-jsherman-opt-Crystal-crystal-src-ecr-process.cr/macro_run  -rdynamic -L/usr/local/bin/../lib/crystal -lgc-threaded -lpthread -lpthread
gmake: [Makefile:254: .build/crystal] Error 1 (ignored)

Couple things to note:

  1. Using a older version of Crystal on the system right now because current pkg for language on freebsd is at 1.10.1
  2. Using FreeBSD version 14.2
  3. The error says can not find library -lgc-threaded, I have not heard or found this library, but I can see that libgc-is correctly installed, available and findable for the system.

Can anyone tell me what I a missing here ?

Thanks

1 Like

Perhaps there is a pkgconf name mismatch?

When I “pkgconf --list-all” is see that the packages are named correctly for freebsd “boehm-gc and boehm-gc-threaded”

Looking in the “lib” directories is see not “lgc-threaded” but see “libgc-threaded” ones.

Running >> >
pkg info boehm-gc-threaded

I see there is a shared object called “libgc-threaded”

What would I look at/for this mismatch ?

Thank you

Yeah, the pkg-conf name is different on freebsd for some reason. Also pkgs are installed in /usr/local/lib which isn’t in LIBRARY_PATH by default.

Starting from Crystal 1.15 we always pass -L/usr/local/lib to cc to ease the pain. For older releases you can workaround it:

export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/lib"
crystal build ...
1 Like

Awesome, I appreciate it. I am also going to put in a ticket for FreeBSD ports maintainer to see if they can update the version of Crystal and Shards packages.

Thanks

3 Likes

I am not super intimate with Github, so forgive me if this sounds dumb.

Cloning master again from the start after the merge for the issue I had with FreeBSD source install, I am checking version and I am getting the following >>>

=================
bin/crystal -v
Using compiled compiler at .build/crystal
Crystal 1.16.0-dev [12f565679] (2025-03-02)

The compiler was not built in release mode.

LLVM: 17.0.6
Default target: x86_64-portbld-freebsd14.1

================

Should I be on the 1.15 version still OR is the 1.16-dev correct. Just was wondering cause I am building some web stuff and its using the 1.16-dev when compiling.

Thanks again.

You compiled the latest crystal master branch which is currently the development branch for the next release (1.16).

You can use it or you might want to get the last release (1.15.1) from the github releases page.

1 Like