Error compiling my first basic Rust program :(

I am a noob to Rust programming. I am getting an error while compiling my first basic Rust program. I presume, I might be making some truly basic mistake. Please advise.

STEPS FOLLOWED:

Installed rustup, rustc, cargo, and Atom editor with ide-rust package.
Logged out and Logged back in.

Created a new package using,

$ cargo new helloworld

Tried compiling the following default program,

fn main() {
println!("Hello, world!");
}

using,

$ rustc main.rs

The following error message is displayed:

error: linking with cc failed: exit code: 1
|
= note:

"cc"
"-m64"
"-arch"
"x86_64"

"-L"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib"
"main.main.7rcbfp3g-cgu.0.rcgu.o"
"main.main.7rcbfp3g-cgu.1.rcgu.o"
"main.main.7rcbfp3g-cgu.2.rcgu.o"
"main.main.7rcbfp3g-cgu.3.rcgu.o"
"main.main.7rcbfp3g-cgu.4.rcgu.o"
"main.main.7rcbfp3g-cgu.5.rcgu.o"
"main.main.7rcbfp3g-cgu.6.rcgu.o"
"main.main.7rcbfp3g-cgu.7.rcgu.o"

"-o"
"main"
"main.4s37gsrti678ik8u.rcgu.o"
"-Wl,-dead_strip"
"-nodefaultlibs"

"-L"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-349f286494d73b18.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-0c9fcc24a503d489.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libobject-70419d92d1ba4b1d.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-65e88774cb68bd46.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libgimli-3849b3781a19a398.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-0dbb03fa66ca6d84.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-65edff8661311c85.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-599e707cd7ee7216.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-40cb05f6c516791a.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-7a0a923a4d37a048.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-7e047938e88325ef.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-02542d835be27c0f.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-63712b18a1365082.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-1196a2a060497e71.rlib"
"/Users/z/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-10db70d883838cbc.rlib"

"-lSystem"
"-lresolv"
"-lc"
"-lm"

= note: xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

It would seem you need to install the Xcode Command Line Tools, in a terminal run this and try again:
xcode-select --install

If authentication fails:
sudo xcode-select --install

2 Likes

Submitted this case as the following bug:

Hopefully we can provide a better output that makes it clearer what you need to do to get things working.

2 Likes

Thx Camden-smallwood for the solution.

Thx for raising the bug, Esteban. I am sure this will help reduce the possibiilty of this type of noob error.

As a side note, the diagnostic/error message that was provided, did not include any 'carriage returns'. It was a single paragraph dump of the message. I had to manually separate each line to make it readable, to try and make sense of the error.

Maybe a noob thing, but useful, I guess :slight_smile:

@samirj would you mind adding some context to the filed ticket? Particularly what your machine is and the specific MacOS version you're running?

Updated my machine spec on Github

1 Like

In addition to the point about xcode-select, you generally also do not need to run rustc directly. 99% of the time, the thing you want to run is cargo build, which will invoke rustc on your behalf with the right combination of arguments for the specific compile targets your project exposes. cargo build should produce a target/debug/helloworld binary that you can run (and cargo run will build it and run it for you).

Cargo also handles dependency tracking and pinning, testing, and documentation generation, and can be extended to handle other project lifecycle tasks.

4 Likes