Brand New to Rust - stuck already

I've just installed Rust on my Mac. I've never used Rust before and apart from a bit of Mac utility scripting I haven't done much coding for a very long time.

I'm looking at this page

In the part with the red background I've got as far as successfully creating the "hello-rust" directory. The next steps don't work. It says

" cargo new generates a "Hello, world!" project for us! We can run this program by moving into the new directory that we made and running this in our terminal: 'cargo run'

So went into hello-rust and typed 'cargo run'

A huge error message resulted.
It starts with "error: linking with cc failed: exit status: 1"
It finishes with "= note: xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun"

And has a lot of stuff in the middle along the lines of (I've not pasted it all)

= note: "cc" "-arch" "x86_64" "-m64" "/var/folders/k4/m2kr_j511316f25h6qxb08rw0000gq/T/rustcrvSt2G/symbols.o" "/Users/xxxx/hello-rust/target/debug/deps/hello_rust-0e916bfd57315816.19ren1f09djijs52.rcgu.o" "/Users/xxxx/hello-rust/target/debug/deps/hello_rust-0e916bfd57315816.283fh6b763prdexb.rcgu.o" "/Users/xxxx/hello-rust/target/debug/deps/hello_rust-0e916bfd57315816.2xcapmqn6617t1j1.rcgu.o" "/Users/xxxx/hello-rust/target/debug/deps/hello_rust-0e916bfd57315816.3k3jkn04auhys4hn.rcgu.o" "/Users/xxxx/hello-rust/target/debug/deps/hello_rust-0e916bfd57315816.4ine916e4c0afx6g.rcgu.o" "/Users/xxxx/hello-rust/target/debug/deps/hello_rust-0e916bfd57315816.hq6al….

………..and……….

"/Users/xxxx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libadler-93f8c992dd4fe422.rlib" "/Users/xxxx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-9838a33e4eec9cf7.rlib" "/Users/xxxx/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-9f7f7415b21b2c00.rlib"

If it helps:

Default host: x86_64-apple-darwin
rustup home: /Users/xxxx/.rustup

stable-x86_64-apple-darwin (default)
rustc 1.65.0 (897e37553 2022-11-02)

If anyone could help me get started then I'd appreciate it. Thanks in advance.

Rust needs a working C toolchain to link against system libraries (which are usually written in C). On a Mac, you will need to install the "Xcode Command-Line Tools". (They have absolutely nothing to do with Xcode, so don't worry – you don't have to download the whole 20+ GB beast. The "Xcode" command line tools are actually just the standard Clang toolchain: the clang and clang++ compilers, a linker, and the required components of the LLVM compiler library, along with some macOS-specific libraries.)

5 Likes

For reference running xcode-select --install should be enough to install the XCode Command-Line Tools.

2 Likes

Thanks for the fast and helpful response H2CO3. Xcode CL tools installed and the error's gone. I've just said hello to the world using Rust.

While I'm here - i there a free editor or IDE you'd recommend?

Thanks again.

Thanks, Bjorn.

A lot of people use VS Code with the Rust Analyzer plugin.

2 Likes

I personally use Vim with a few customizations for writing Rust, and it works well for me.

These are some of the most popular IDEs and text editors:

Some of them should be suitable for coding in Rust but I personally use micro which is missing on this list.

Edit: This is written in Rust:

1 Like

Unfortunately this is one of those questions that tends to autostimulate everyone to take their own favourite dog for a walk. I use neovim, but wouldn't recommend it for most people starting afresh.

The conventional (and IMO wisest) advice is to use what you already know. Learning any new language is enough of a challenge. You don't want to add unnecessarily to the burden. Most of the widely used editors support Rust well enough to get started with.

However, given you write

perhaps you're not still familiar enough with any particular editor to easily jump into? If so, I'd suggest VSCode. It has so dominated recent mindshare (for better or worse) that all tooling has to work well with it. It's easy to get started with. If later down the track you decide you prefer something else, you won't have sunk too many costs.

3 Likes

Thanks to all for the help and suggestions. The last editor I used in anger was in VMS, so I'm up and running in VS.

Thanks again.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.