Can't compile in Rust

Hello I'm new in rust, a few month ago I was learning rust and everything it's fine when I compiling rust file but after few weeks I want to continues my learning I'm getting error when compiling file rust.
I'm using ubuntu 20.04
rust version : rustc 1.71.0 (8ede3aae2 2023-07-12)
have installed gcc and build-essential

the error appear when compiling like this:

and after error, then appear file like this:

The error is telling you that you're missing a linker, which is a required component of building Rust code.

It's been a little while since I've used ubuntu, but try installing the gcc package (which contains a linker IIRC) with sudo apt get install gcc and then rebuilding your Rust project.

1 Like

I have been installing gcc anyway

cc is a CLI program, one can just try to run it to find out whether it's installed:

$ which cc
/usr/bin/cc
$ cc
cc: fatal error: no input files
compilation terminated.
2 Likes

Well, "Invalid params" isn't exactly a helpful message. Perhaps you get better hints when running more verbosely:

rustc -v file.rs
# or
rustc -g file.rs

And of course it's always a good idea to update packages when things don't work as expected:

sudo apt-get update
sudo apt-get upgrade
1 Like

rustc -v doesn’t add much to the linker call. For more about linking, you need to enable extra logging:

RUSTC_LOG=rustc_codegen_ssa::back::link=info rustc file.rs
1 Like

That brings up a question: why is OP calling rustc directly, rather than cargo? For a beginner, or Indeed anyone who needs help building a project, this is almost certainly the wrong thing to do. Rust is not C, and rustc is not gcc or llvm.

The better way to proceed is to create a cargo project, eg:

cargo new --lib my-project 
cd my-project 

Then navigate to `my-project/src/lib.rs, add the code there, and execute at a bash/cmd/PS prompt:

cargo build
3 Likes

good gwief! your PATH is all fsck up.

if you can't bring back your original environment try another username with access to development tools.

1 Like

Hi thanks for your answer.
anyway I have been installing webmethods CommandCentral which also have cc

and after I'm uninstall this command central, everything going back work.
Thank you so much :wink:

1 Like

that it's work! hehehe

1 Like

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.