Rust not compiling to executable in Linux

rust cross compile
rust programs

Compiling rust on Linux with rustc or cargo build produces a shared library instead of an executable file. My file manager (thunar) and file command show that file type as shared library.

And the compiled binary can only be executed via terminal by $ /path/to/file or $ cargo run. That file cannot be executed just by double clicking as other executables can be. Output from file command:

$ file rust_bin

rust_bin: ELF 64-bit LSB shared object, x86_64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=cb8cd... , with debug_info, not stripped`

  1. Your compiler produces an executable file. There is no big difference between a shared library and a dynamically linked executable file. They follow the same basic format. The string interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0 indicates that this is an executable and not a library. Libraries don't normally have an interpreter set. Try running file on some files you know are executables, and some other files you know are libraries, and see for yourself. An interpreter is usually a small system program that loads and executes a shared object. A file can actually serve as both a library and an executable at the same time (the most common example is your libc.so.6 or whatever it is called on your system; try running it).
  2. If you can run this executable from your shell but not from your file manager, the problem is with the file manager, not with the executable. You may have to specifically instruct the file manager that your program should run in a terminal. This usually can be done by creating a .desktop file that describes your program. In addition, desktop tools may mis-recognise modern executables as shared libraries. This is a common problem. It too can be remedied by creating a .desktop file for your executable. It is not specific to rust in any way.

Bottom line, there's nothing wrong with rustc or cargo or the way you are running them.

Rust not compiling to executable in Linux, Compiling rust on Linux with rustc or cargo build produces a shared library instead of an executable file. Loaded plugin Rust v2.0.4025 by Oxide and Contributors Loaded plugin Unity v2.0.3756 by Oxide and Contributors Added '// Reference: Facepunch.Sqlite' in plugin 'ImageLibrary' Added '// Reference: UnityEngine.UnityWebRequestModule' in plugin 'ImageLibrary' Couldn't check for update to Compiler.exe Error: ConnectFailure (Et tilkoblingsforsøk

When you create your project initially you can simply use cargo new (or init) to get the right type

cargo new my_project_name
# OR create a lib project
cargo new --lib my_library_name

when you use rustc you can use a command-line option

rustc lib.rs
# lib.rs has to contain a main function
# OR to build a lib
rustc --crate-type=lib lib.rs

Your finding about shared object is misleading your error hunt: https://askubuntu.com/questions/690631/executables-vs-shared-objects - it's not a problem, an executable can be a shared object.

I think in your case the problem is another. What does you binary do? Does basically just print something via stdout and that's it? Maybe this is the reason why double clicking in the gui file browser does not show you anything, it runs a millisecond and is over before you know it.

Have you tried waiting for input at the end of the main function? Just so that the user can read the output and hit Return key.

use std::io;
fn main() {
    // do and print stuff

    // Wait for return key
    let mut input = String::new();
    match io::stdin().read_line(&mut input);
}

Not sure how thunar will deal with it but eventually he will open a terminal and show the result and close the terminal when enter is pressed.

Will an executable compiled on Linux distr. A work on all other Linux , If I compile a rust app on say Fedora or Arch or whatever else, will it work on code is not pure Rust, then you'll need to set up a musl-libc cross-compilation  Rust uses static linking to compile its programs, meaning that all libraries required by even the simplest Hello world! program will be compiled into your executable. This also includes the Rust runtime.

cargo build

creates an executable file in target/debug/rust_bin Then just

./target/debug/hello_cargo # or .\target\debug\hello_cargo.exe on Windows

to execute, or just

cargo run

PS: you need to create a Cargo.toml file with the appropriate data inside.

How to distribute programs written in Rust as binaries? : rust, I'm not even sure how many different binaries I need. But I'm not sure if I also need to differentiate between 32 bit and 64 architectures and linux and mac etc. Is there a Or do I need to compile on the target platform to get the correct binary ? [1] you know, likeactually putting a real executable file on a server for folks to  The Rust distribution only provides compiled libraries for the host system. However, according to Arch Linux’s wiki page on Rust, you could copy the compiled libraries from the Windows packages in the download directory (note that there are i686 and x86-64 packages) in the appropriate place on your system (in /usr/lib/rustlib or /usr/local/lib/rustlib, depending on where Rust is installed

Building Rust programs for Windows on Debian Linux, Unlike many other compilers (such as gcc ), every copy of the Rust compiler can crate for `std` | = note: the `x86_64-pc-windows-gnu` target may not be installed … Install the package that teaches Linux to use Wine when trying to run .exe:. According to the Rust 2019 survey, improving compile times is #4 on the Rust wishlist: Rust Survey results 2019. (Obligatory xkcd.) But all hope is not lost! Below is a list of tips and tricks on how to make your Rust project compile faster today. They are roughly ordered by practicality, so start at the top and work your way down until you're

Packaging and distributing a Rust tool, Not quite. We still need to make sure the binaries we build are compatible with as many systems as possible. For example, on Linux we can compile not for the  The Rust distribution only provides compiled libraries for the host system. However, according to Arch Linux's wiki page on Rust, you could copy the compiled libraries from the Windows packages in the download directory (note that there are i686 and x86-64 packages) in the appropriate place on your system (in /usr/lib/rustlib or /usr/local/lib/rustlib, depending on where Rust is installed

Taking Rust everywhere with rustup, You want your Linux-based build servers to produce binaries for all the platforms you That functionality is not shipping today, but it's something we hope to let's walk through compiling a statically-linked Linux executable. Preface & Content. The rust compiler supports various targets with a few simple installation steps without the need to write specialized code. The following article will guide you throught the setup of a fully functional toolchain to write cross-compiled rust applications which will run on a large number of linux distributions.

Comments
  • Please show what exact commands you are running and what exact messages they produce.
  • It is executable, it can be executed in terminal ./file but not from file manager(thunar xfce4), seems like file manager is not recognizing shared libraries and not executing them as other executables can be executed just from the file manager and produce same output from file commamd. I found something related on launchpad.net Shared libraries not being executed by file mamagers
  • @Amiy "seems like file manager is not recognizing shared libraries". No, this is not what happens here. The file is an executable and not a shared library. The bug reports talks about a bug/misconfiguration in the GUI. It thinks the file is a shared library, when it isn't. Nothing to do with rustc really.
  • @Amiy Apparently this is a common bug. On my machine I cannot run any executable from a file manager. I never use a file manager so I wouldn't have discovered it on my own.
  • RUSTFLAGS="-C relocation-model=dynamic-no-pic link-args=-no-pie" cargo build produces an executable.And gcc -no-pie src.c for gcc .I generally use vim or nano but I just tried today to execute it from file manager and it didn't.As I was thinking that if I give the binary to someone else they won't be able to execute it without opening terminal.This happens also with programmes compiled with GCC whether I use -no-pie option or not.So The problem is with GUI file managers.
  • @Amiy if you give your program to someone and you expect them to use GUI, you should also give them a .desktop file and an icon anyway.