Hey I am trying to run roc repl
on my M1 Mac and I'm getting a linking error.
I'm on the latest main
branch and I'm in a shell with nix develop
roc git:main
❯ RUST_BACKTRACE=1 cargo run repl
Finished dev [unoptimized + debuginfo] target(s) in 0.54s
Running `target/debug/roc repl`
The rockin’ roc repl
────────────────────────
Enter an expression, or :help, or :q to quit.
» 123
ld: library not found for -lSystem
/tmp/nix-shell.7EFLj3/.tmpuOXr3x/app.dylib: No such file or directory
thread 'main' panicked at '
___________
Linking command failed with status ExitStatus(unix_wait_status(256)):
Child { stdin: None, stdout: None, stderr: None, .. }
___________
', crates/compiler/build/src/link.rs:1305:5
stack backtrace:
0: rust_begin_unwind
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
1: core::panicking::panic_fmt
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
2: roc_build::link::llvm_module_to_dylib
at ./crates/compiler/build/src/link.rs:1305:5
3: roc_repl_cli::cli_gen::mono_module_to_dylib
at ./crates/repl_cli/src/cli_gen.rs:290:5
4: roc_repl_cli::cli_gen::gen_and_eval_llvm
at ./crates/repl_cli/src/cli_gen.rs:86:9
5: roc_repl_cli::repl_state::ReplState::eval_and_format
at ./crates/repl_cli/src/repl_state.rs:242:46
6: roc_repl_cli::repl_state::ReplState::step
at ./crates/repl_cli/src/repl_state.rs:104:46
7: roc_repl_cli::main
at ./crates/repl_cli/src/lib.rs:49:23
8: roc::main
at ./crates/cli/src/main.rs:215:35
9: core::ops::function::FnOnce::call_once
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
I'll take a look in a bit
Hmm, I could not reproduce this with the latest main on my m1 mac mini with:
nix develop
cargo run repl
123
What macos version are you on?
13.5
I'm on macOS 12, so I would expect this to be a macOS 13 issue.
I'm on macOS 13.5.1 and it just worked for me when I ran:
nix develop
cargo run repl
123
sometimes I've found things work better if I do rm -f flake.lock
on main
- takes awhile to re-download things though
Ah ok, I'll try that
When I'm back at my computer
Nope, I'm still getting the same error :disappointed:
Also tried cargo clean
- no joy
Strange :thinking:
I think I may have found a workaround @Brian Carroll , can you try the following commands in the same terminal:
> export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
> export LIBRARY_PATH="$LIBRARY_PATH:$SDKROOT/usr/lib"
> roc repl
Thanks so much for digging into this!
I tried those commands and they didn't work, unfortunately.
That directory does have a libSystem.tbd
file in it
Apparently that means "text based description".
The other day while researching this, I found out that Apple no longer put their system libraries in the actual filesystem, since a few versions ago. They are in some other hidden cache. I guess still on disk but not in the filesystem.
So you can't find it with ls
but if you call dlopen
on it, the linker knows how to get it.
Apparently it was to help you use your Mac to develop iOS apps with a different libc or something.
They put these .tbd files in the filesystem though.
Anyway I'm not sure where that gets us exactly
It just makes it more confusing how something could possibly not find libSystem
. I guess somebody somewhere wrote some code that is not looking it up the way Apple think you should, and it's not working. But why so specific to the OS version?
It's a weird one.
I have finished the PR I was working on where I made changes to the CLI REPL so this isn't holding me up.
I can live with it for now. Maybe best to see if anyone else runs into it.
Someone already has :p #5797
I'm working on setting up some tests to check if it reproduces on github's CI machines.
It did not reproduce on githubs's CI machines...
I guess I could try it on my sister's laptop
Hey I haven't done any code contributions for quite a long time but today I tried to start working on something again.
But I came up against this issue again!
I can't run any Roc program natively on my M1
❯ roc examples/helloWorld.roc
Downloading https://github.com/roc-lang/basic-cli/releases/download/0.8.1/x8URkvfyi9I0QhmVG98roKBUs_AZRkLFwFJVJ3942YA.tar.br
into /Users/briancarroll/.cache/roc/packages
[24.0 / 24.0 MB]
ld: library 'System' not found
examples/helloWorld: No such file or directory
thread 'main' panicked at 'not yet implemented: gracefully handle `ld` (or `zig` in the case of wasm with --optimize) returning exit code Some(1)', crates/compiler/build/src/program.rs:1044:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I wonder if there's a way of rebuilding all the Roc related Nix stuff from scratch. I know Nix is not meant to need things like that, but it is not meant to have errors like this either.
One problem with that is I might have to redo it for my work stuff too.
I can run Wasm tests and that might actually be enough for what I want to do anyway.
But I am blocked from doing any natively built stuff with Roc.
Might mean you need to update xcode or something else on your mac.
I think system is part of what xcode installs, but that could be wrong/me misremembering
Hmm. I checked Xcode on the App Store as it shows updates when they're available. But nothing showing.
I started thinking about whether I could try using a different linker. I figured the first step was to find out which one I'm currently running.
In my Nix shell for Roc, I get
❯ which ld
/nix/store/vwh2qqal1q101wv4jy40giavp73q0msd-clang-wrapper-16.0.6/bin/ld
But in a "normal" shell, I get /usr/bin/ld
Can I convince Roc to use a different one?
I guess I could hack the source but that rabbit hole always goes pretty deep
Or can I get it to print what commands it's using? Then I could play around with command options.
We don't expose any of that currently, but link.rs has the command
In link_macos I think
Right, I'll have a look. Might be good to have a debug env var for this
https://github.com/roc-lang/roc/pull/6508
:point_up: Add a debug flag for build commands
Were you able to solve this issue @Brian Carroll?
No!
Is this error happening when the roc binary is invoking the linker to build a platform? (Not when building the roc binary itself?)
No I think it's when it links platform to app. The repl uses a precompiled platform. I posted repro commands at the top of the thread.
Huh, I'm curious how ld
is being found when the command is having its environment cleared (& doesn't inherit from the spawning process): https://github.com/roc-lang/roc/blob/main/crates/compiler/build/src/link.rs#L1114
Does /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd
exist on your machine Brian?
xcode-select --install
to get the "command line tools" might be the solution here. (Though it sounds like you may have already tried that. :shakes-fist-at-macos:)
I'm not home right now, will check when I can. I looked up various paths like that before, not sure if this one specifically. Thanks for looking into this!
Also I noticed in the Rust docs
https://doc.rust-lang.org/std/process/struct.Command.html#method.env_clear
Clears all explicitly set environment variables and prevents inheriting any parent process environment variables.
So maybe this doesn't clear the default PATH.
Hi there. I am new to roc and also encountered this issue. I'm trying to get a hello world program running on an M2 mac using nix. Here's a repo with my flake.nix and single roc module. https://github.com/bromanko/roc
I tried adding the same set of libraries in the roc-lang repo's nix build as buildInputs but it didn't help.
Hi @bromanko,
I believe your repo is set to private visibility
Doh. Fixed.
Sorry @bromanko, I tried your flake on my arm64 mac (macos 14) and I could not reproduce the issue.
Thanks for that confirmation. I checked software update and I had a pending Command Line utilities update. Updating it would complete then show I still had a Command Line update pending. After repeating the process three times I restarted. The update is gone along with the error. Not sure what was going on but hopefully this helps if anyone else has the same problem.
Last updated: Jul 06 2025 at 12:14 UTC