Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.
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`

like image 744
Avm-x Avatar asked Oct 21 '25 12:10

Avm-x


1 Answers

  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.

like image 58
n. 1.8e9-where's-my-share m. Avatar answered Oct 23 '25 04:10

n. 1.8e9-where's-my-share m.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!