Stream: compiler development

Topic: Missing -lSystem for REPL on Mac


view this post on Zulip Brian Carroll (Sep 09 2023 at 08:52):

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.

view this post on Zulip Anton (Sep 09 2023 at 09:30):

I'll take a look in a bit

view this post on Zulip Anton (Sep 09 2023 at 10:20):

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?

view this post on Zulip Brian Carroll (Sep 09 2023 at 11:02):

13.5

view this post on Zulip Anton (Sep 09 2023 at 11:50):

I'm on macOS 12, so I would expect this to be a macOS 13 issue.

view this post on Zulip Richard Feldman (Sep 09 2023 at 19:54):

I'm on macOS 13.5.1 and it just worked for me when I ran:

nix develop
cargo run repl
123

view this post on Zulip Richard Feldman (Sep 09 2023 at 19:55):

sometimes I've found things work better if I do rm -f flake.lock on main - takes awhile to re-download things though

view this post on Zulip Brian Carroll (Sep 10 2023 at 13:23):

Ah ok, I'll try that

view this post on Zulip Brian Carroll (Sep 10 2023 at 13:24):

When I'm back at my computer

view this post on Zulip Brian Carroll (Sep 10 2023 at 17:15):

Nope, I'm still getting the same error :disappointed:

view this post on Zulip Brian Carroll (Sep 10 2023 at 17:22):

Also tried cargo clean - no joy

view this post on Zulip Anton (Sep 11 2023 at 09:04):

Strange :thinking:

view this post on Zulip Anton (Sep 12 2023 at 09:56):

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

view this post on Zulip Brian Carroll (Sep 12 2023 at 17:44):

Thanks so much for digging into this!
I tried those commands and they didn't work, unfortunately.

view this post on Zulip Brian Carroll (Sep 12 2023 at 17:44):

That directory does have a libSystem.tbd file in it
Apparently that means "text based description".

view this post on Zulip Brian Carroll (Sep 12 2023 at 17:44):

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.

view this post on Zulip Brian Carroll (Sep 12 2023 at 17:45):

They put these .tbd files in the filesystem though.

view this post on Zulip Brian Carroll (Sep 12 2023 at 17:45):

Anyway I'm not sure where that gets us exactly

view this post on Zulip Brian Carroll (Sep 12 2023 at 17:46):

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?

view this post on Zulip Brian Carroll (Sep 12 2023 at 17:46):

It's a weird one.

view this post on Zulip Brian Carroll (Sep 12 2023 at 17:47):

I have finished the PR I was working on where I made changes to the CLI REPL so this isn't holding me up.

view this post on Zulip Brian Carroll (Sep 12 2023 at 17:47):

I can live with it for now. Maybe best to see if anyone else runs into it.

view this post on Zulip Anton (Sep 12 2023 at 18:30):

Someone already has :p #5797

view this post on Zulip Anton (Sep 12 2023 at 18:30):

I'm working on setting up some tests to check if it reproduces on github's CI machines.

view this post on Zulip Anton (Sep 19 2023 at 14:30):

It did not reproduce on githubs's CI machines...

view this post on Zulip Anton (Sep 19 2023 at 14:31):

I guess I could try it on my sister's laptop

view this post on Zulip Brian Carroll (Feb 04 2024 at 15:43):

Hey I haven't done any code contributions for quite a long time but today I tried to start working on something again.

view this post on Zulip Brian Carroll (Feb 04 2024 at 15:43):

But I came up against this issue again!

view this post on Zulip Brian Carroll (Feb 04 2024 at 15:43):

I can't run any Roc program natively on my M1

view this post on Zulip Brian Carroll (Feb 04 2024 at 15:44):

❯ 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

view this post on Zulip Brian Carroll (Feb 04 2024 at 15:50):

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.

view this post on Zulip Brian Carroll (Feb 04 2024 at 15:51):

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.

view this post on Zulip Brendan Hansknecht (Feb 04 2024 at 17:16):

Might mean you need to update xcode or something else on your mac.

view this post on Zulip Brendan Hansknecht (Feb 04 2024 at 17:17):

I think system is part of what xcode installs, but that could be wrong/me misremembering

view this post on Zulip Brian Carroll (Feb 04 2024 at 17:34):

Hmm. I checked Xcode on the App Store as it shows updates when they're available. But nothing showing.

view this post on Zulip Brian Carroll (Feb 04 2024 at 19:29):

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?

view this post on Zulip Brian Carroll (Feb 04 2024 at 19:30):

I guess I could hack the source but that rabbit hole always goes pretty deep

view this post on Zulip Brian Carroll (Feb 04 2024 at 19:31):

Or can I get it to print what commands it's using? Then I could play around with command options.

view this post on Zulip Brendan Hansknecht (Feb 04 2024 at 19:34):

We don't expose any of that currently, but link.rs has the command

view this post on Zulip Brendan Hansknecht (Feb 04 2024 at 19:34):

In link_macos I think

view this post on Zulip Brian Carroll (Feb 04 2024 at 20:04):

Right, I'll have a look. Might be good to have a debug env var for this

view this post on Zulip Brian Carroll (Feb 06 2024 at 07:45):

https://github.com/roc-lang/roc/pull/6508

view this post on Zulip Brian Carroll (Feb 06 2024 at 07:45):

:point_up: Add a debug flag for build commands

view this post on Zulip Anton (Mar 25 2024 at 10:33):

Were you able to solve this issue @Brian Carroll?

view this post on Zulip Brian Carroll (Mar 25 2024 at 10:35):

No!

view this post on Zulip Jonathan Schear (Mar 25 2024 at 18:04):

Is this error happening when the roc binary is invoking the linker to build a platform? (Not when building the roc binary itself?)

view this post on Zulip Brian Carroll (Mar 25 2024 at 18:13):

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.

view this post on Zulip Jonathan Schear (Mar 25 2024 at 18:41):

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

view this post on Zulip Jonathan Schear (Mar 25 2024 at 18:48):

Does /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd exist on your machine Brian?

view this post on Zulip Jonathan Schear (Mar 25 2024 at 18:51):

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:)

view this post on Zulip Brian Carroll (Mar 25 2024 at 18:54):

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.

view this post on Zulip bromanko (Jun 07 2024 at 23:16):

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.

view this post on Zulip Anton (Jun 08 2024 at 08:45):

Hi @bromanko,
I believe your repo is set to private visibility

view this post on Zulip bromanko (Jun 08 2024 at 14:02):

Doh. Fixed.

view this post on Zulip Anton (Jun 10 2024 at 17:43):

Sorry @bromanko, I tried your flake on my arm64 mac (macos 14) and I could not reproduce the issue.

view this post on Zulip bromanko (Jun 11 2024 at 03:47):

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