Stream: beginners

Topic: ✔ Roc test: "Linking command failed"


view this post on Zulip Hannes (Apr 25 2023 at 05:22):

Hi everyone, I'm using the latest nightly build of Roc:

 roc --version
roc nightly pre-release, built from commit 28146c9 on Mo 24 Apr 2023 09:08:22 UTC

And I have a MWE project with these files:

src/main.roc

package "Example"
    exposes [HelloWorld]
    packages {}

src/HelloWorld.roc

interface HelloWorld exposes [greet] imports []

greet = \person -> "Hello, \(person)."

expect greet "World" == "Hello, World."

When I run Roc test like this:

 roc test src/main.roc

I get this error:

ld: cannot find -lc
ld: cannot find -lm
ld: cannot find -lpthread
ld: cannot find -ldl
ld: cannot find -lrt
ld: cannot find -lutil
ld: cannot find -lc_nonshared
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:1392:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

view this post on Zulip Luke Boswell (Apr 25 2023 at 05:23):

Might be related, but I am pretty sure there is a bug when you try and run roc cli in the same directory as a package file.

view this post on Zulip Luke Boswell (Apr 25 2023 at 05:24):

This is why I usually create packages in a /package folder i.e. /package/main.roc and then when I run it I use roc test ./package/Example

view this post on Zulip Hannes (Apr 25 2023 at 05:25):

I've just tried running

roc test example/src/main.roc

and I got the same error :/

view this post on Zulip Luke Boswell (Apr 25 2023 at 05:25):

Otherwise I don't see any issues with your code. It may be a compiler issue.

view this post on Zulip Luke Boswell (Apr 25 2023 at 05:26):

I don't know if you can run roc test on a package file, can you try it on the interface directly?

view this post on Zulip Luke Boswell (Apr 25 2023 at 05:27):

There is an open issue for roc test to find and test all modules in a package.

view this post on Zulip Hannes (Apr 25 2023 at 05:28):

I'll add that I'm on Ubuntu 23.04, but I was also getting this error on Ubuntu 22.10 last week as well, so I don't think it's specific to this version of Ubuntu.

view this post on Zulip Hannes (Apr 25 2023 at 05:28):

Just tried

roc test src/HelloWorld.roc

and got the same error again

view this post on Zulip Luke Boswell (Apr 25 2023 at 05:30):

Screen-Shot-2023-04-25-at-15.29.30.png

% roc test package/HelloWorld.roc

0 failed and 1 passed in 657 ms.

Looks like a compiler issue. Not sure I can help you much further.

view this post on Zulip Hannes (Apr 25 2023 at 05:31):

Thanks for your suggestions, I'll try some other stuff and report back :)

view this post on Zulip Luke Boswell (Apr 25 2023 at 05:32):

If you can build from source, using e.g. nix develop then cargo run --release --locked and using roc in /targets/release etc that might be the.most reliable

view this post on Zulip Hannes (Apr 25 2023 at 08:47):

Ah, so I compiled roc from source in nix develop and roc test ran fine, then I moved it to my path and ran it and it worked, then I downloaded the nightly build and ran it inside the nix shell and it still worked, but none of these worked outside the nix shell! Seems to be something specific to my setup, no idea what it could be though :shrug:

view this post on Zulip Anton (Apr 25 2023 at 09:25):

I do think it is caused by changes in Ubuntu 23.04, can you make an issue for this @Hannes?

view this post on Zulip Hannes (Apr 25 2023 at 15:53):

Sure, I'll also try and recreate the bug in a clean Ubuntu VM with a few different versions and add that to the issue

view this post on Zulip Hannes (Apr 28 2023 at 08:37):

I've created issue #5340 for this and I've confirmed that it works on Ubuntu 22.04 but not on 23.04 as @Anton suspected.

view this post on Zulip Anton (Apr 28 2023 at 10:46):

Thanks for checking this @Hannes, does roc run src/main.roc work on 23.04?

view this post on Zulip Hannes (Apr 28 2023 at 13:37):

It works in that it doesn't crash, but I get the "could not find platform" error, which makes sense because it's a library.

view this post on Zulip Anton (Apr 28 2023 at 13:39):

Oh yes, that makes sense, it's an interface, I looked over that. Does the hello world app work on 23.04?

view this post on Zulip Hannes (Apr 28 2023 at 13:42):

Yes, I haven't had that error with building/running apps, but when I put the expect in a hello world app and run roc test I get the same crash:

app "hello-world"
    packages {
        pf: "https://github.com/roc-lang/basic-cli/releases/download/0.3.1/97mY3sUwo433-pcnEQUlMhn-sWiIf_J9bPhcAFZoqY4.tar.br",
    }
    imports [pf.Stdout]
    provides [main] to pf

greet = \person -> "Hello, \(person)!"

expect greet "World" == "Hello, World."

main = Stdout.line (greet "World")
❱ roc test hello-world.roc
ld: cannot find -lc
ld: cannot find -lm
ld: cannot find -lpthread
ld: cannot find -ldl
ld: cannot find -lrt
ld: cannot find -lutil
ld: cannot find -lc_nonshared
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:1396:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

view this post on Zulip Brendan Hansknecht (Apr 28 2023 at 13:45):

Can you try roc run --linker=legacy {some app}?

view this post on Zulip Hannes (Apr 28 2023 at 14:14):

Running the hello-world app with the legacy linker gives this crash:

❱ roc run --linker=legacy hello-world.roc
ld: cannot find -lc
ld: cannot find -lm
ld: cannot find -lpthread
ld: cannot find -ldl
ld: cannot find -lrt
ld: cannot find -lutil
ld: cannot find -lc_nonshared
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:1004:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

view this post on Zulip Brendan Hansknecht (Apr 28 2023 at 14:19):

cool. That is what I wanted to check, just to verify.

view this post on Zulip Brendan Hansknecht (Apr 28 2023 at 14:23):

Can you make sure you have build-essential installed and test again? That should at least fix -lc, but I would expect ubuntu to have headers for libc install by default, so idk.

view this post on Zulip Hannes (Apr 28 2023 at 14:28):

I'm getting

build-essential is already at the latest version 12.9ubuntu3

view this post on Zulip Brendan Hansknecht (Apr 28 2023 at 14:33):

hmm..ok

view this post on Zulip Brendan Hansknecht (Apr 28 2023 at 14:36):

These should all be installed libraries by default on most linux systems. On top of that, we are just calling the system ld here, so it should be able to find them. build-essential definitely installs the stuff for libc dev. Really weird.

view this post on Zulip Hannes (Apr 29 2023 at 05:22):

Okaaayyyyyyy, I've figured out why it wasn't working, turns out I had another version of GNU binutils installed which had presedence over the system package, and once I removed that directory from my PATH it works fine now! Thanks everyone who looked into this, I'll close the issue as well.

view this post on Zulip Notification Bot (Apr 29 2023 at 05:23):

Hannes has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC