·5 min read
A Crystal image that built fine but could not link: the tarball's static libgc
The Crystal image built, crystal --version printed a version, and a program that linked against the garbage collector was the thing that would not link. The cause was a static library inside the official Crystal tarball that had been built against a newer glibc than the Debian release my image is based on. The fix is one rm -f line, and the reason it works is worth spelling out.
- Project
- Pterodactyl yolks
- Date
- Oct 2026
- Stack
- Docker, Debian bookworm, Crystal, GitHub Actions
- Commit
- e028013
What the image is for
This is one of my custom Docker images for Pterodactyl, the game-server panel whose Wings daemon runs containers. A user uploads a Crystal project, and the start script builds it and runs it. So the image has to hold a working compiler, shards, and everything the compiler links against, all on a base I control. I use debian:bookworm-slim for these.
Crystal does not compile to a self-contained binary by itself. It generates LLVM output and then links with the system C toolchain against C libraries. The Dockerfile therefore installs the headers for the ones the standard library and common shards use:
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates curl git gcc g++ make pkg-config \
libssl-dev libpcre2-dev libgc-dev libevent-dev libyaml-dev \
libxml2-dev zlib1g-dev libgmp-dev libsqlite3-dev libpq-dev \
tini tzdata iproute2 \
&& rm -rf /var/lib/apt/lists/*OpenSSL, PCRE2, libgc, libevent, libyaml, libxml2, zlib and GMP are the ones the image comment names. SQLite and PostgreSQL client headers are there because those are the database shards people reach for first.
The tarball carries its own libgc
The compiler comes from the official release tarball on GitHub, not from a Debian package. The URL is built from the CRYSTAL_VERSION build argument and the target architecture:
ARG CRYSTAL_VERSION=1.22.0
ARG TARGETARCH
...
case "${TARGETARCH:-amd64}" in \
amd64) arch=x86_64 ;; \
arm64) arch=aarch64 ;; \
*) echo "unsupported arch ${TARGETARCH}" >&2; exit 1 ;; \
esac; \
curl -fsSL -o /tmp/crystal.tar.gz \
"https://github.com/crystal-lang/crystal/releases/download/${CRYSTAL_VERSION}/crystal-${CRYSTAL_VERSION}-1-linux-${arch}.tar.gz"; \Inside that tarball, next to the compiler, is lib/crystal/libgc.a, a static build of the Boehm garbage collector. When you link a Crystal program, the linker finds that archive in the compiler's own library directory and uses it before it looks at the system libraries. That is convenient on the machine the tarball was built for.
The problem is stated in the comment I left in the Dockerfile: the tarball's static libgc was built against a newer glibc than bookworm's, and it asks for __isoc23_strtol. That symbol comes from glibc 2.38, which changed how strtol and related functions behave when C23 binary literals are enabled, so code compiled against the newer headers references the __isoc23_ variants. Bookworm ships glibc 2.36, which does not have them. The result is an undefined reference at link time. It does not show up when the compiler starts or when you print its version, only when a program is linked, and that is why a build check that only runs crystal --version would pass.
The fix
rm -f /opt/crystal/lib/crystal/libgc.a; \
ln -s /opt/crystal/bin/crystal /usr/local/bin/crystal; \
ln -s /opt/crystal/bin/shards /usr/local/bin/shards; \
crystal --version; shards --versionWith the bundled archive gone, the linker falls through to the system's libgc, which is why libgc-dev is in the package list. Debian's libgc is built against Debian's glibc, so the symbol it wants exists. I preferred this to the alternative of moving the image to a newer Debian release: the rest of my images share the same base, and a newer base would mean re-validating all of them for one library.
I want to be honest about what the commit shows. The commit message does not record the exact link error, and the rm -f line was written with the explanation in the Dockerfile rather than a test. What I can verify from the repo is the comment, the removal, and the package that replaces the archive. I am explaining the glibc side from how those symbols are versioned, not quoting a build log.
Why the tarball, and the version matrix
Taking the official tarball, rather than a distribution package, lets a build argument pin the exact compiler version, and shards comes in the same tarball. The workflow builds a matrix of two versions and tags them:
matrix:
include:
- version: 1.22.0
tags: crystal_1.22,crystal_latest
- version: 1.21.1
tags: crystal_1.21Each image is built for linux/amd64 and linux/arm64, with a monthly scheduled rebuild so Debian security updates reach the base. The arm64 build maps TARGETARCH to aarch64, which is the name in the tarball, not arm64. The same libgc removal applies to both architectures, because it happens after extraction.
Keeping compile memory in check
The start script builds with shards build --release and passes --threads=N, where N is taken from the container's cgroup CPU quota. Crystal's codegen threads each hold an LLVM module in memory at once, so on a panel server limited to one CPU, running one per host core would multiply peak memory. The script reads /sys/fs/cgroup/cpu.max, rounds the quota up to whole CPUs, and passes nothing when the quota is max. Compile cache goes to CRYSTAL_CACHE_DIR=/home/container/.cache/crystal, inside the one directory the panel preserves.
What I would check next time
A compiler image should be tested by compiling something that links, not just by printing a version. The libgc problem is exactly the kind of failure that a --version smoke test cannot see. The lesson I took is to treat any prebuilt static archive inside a toolchain tarball as part of the target system's ABI, and to check it against the base image's glibc before shipping. When the two do not match, the cheapest fix is often to delete the vendored copy and let the linker use the one your distribution already built for itself.
#docker#crystal#glibc#linker#pterodactyl
Keep reading
Have a project in mind?