Rust static compilation does not work on different CPU architectures

Hi guys.

Just straight to the problem, I have two computers, one's CPU was Intel(R) Core™ i5-10400F CPU @ 2.90GHz and another is Intel(R) Xeon(R) Silver 4110 CPU @ 2.10GHz, and the first one is my desktop work computer which running Ubuntu22.04 and KVM, the second is my Linux server which running Debian Testing and KVM, I wanna to build my program on my Ubuntu22.04 and run at my Linux server, but it failed, I've tested a lot to figure out the problem, and I found the key point to this problem is the CPU arch was different...here is my test step:

  • first I run this program in my Ubuntu22.04, it work very well.
  • then I run this program in my Debian11 hosted by KVM in my Ubuntu22.04 computer, it work well too.
  • finally I run this program in my Linux server both rare machine and virtual machine (Debian11 and KVM), it failed...raise some error like this -bash: ./mytest: cannot execute binary file: Exec format error

More information:

  • compilation with command cargo build --release --target=x86_64-unknown-linux-musl
  • my test code
fn main() {
    println!("Hello, world!");
}

can you post the command ?
uname -a
in the linux that is showing the error

Yes, thanks for your reply, here is output.

Desktop

Linux jay-Vostro-3881 5.15.0-36-generic #37-Ubuntu SMP Tue May 31 17:01:58 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Debian 11 hosted by my desktop

Linux debian 5.10.0-14-amd64 #1 SMP Debian 5.10.113-1 (2022-04-29) x86_64 GNU/Linux

Linux server

Linux h6 5.17.0-1-amd64 #1 SMP PREEMPT Debian 5.17.3-1 (2022-04-18) x86_64 GNU/Linux

Debian 11 hosted by server

Linux debian 5.10.0-14-amd64 #1 SMP Debian 5.10.113-1 (2022-04-29) x86_64 GNU/Linux

Can you post the ?

file ./mytest

in one machine that is working and in the linux server that is doing wrong

Oh, yes.

My desktop

mytest: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), static-pie linked, BuildID[sha1]=f4ad56ab8b65564edeb30421d305a9cb5ddbaa9d, with debug_info, not strippe

Linux server

mytest: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), too many program (2573)

There are different...

can you tell me the size of the two binaries

it's the same? because i'm thinking about something have gone wrong in the copy

Oh, they are different, I use the du command.

Desktop

3812    mytest

Linux server

3820	mytest

I found the problem, I use a FTP server to transform the binary file to my Linux server, now I just using the scp command, the file size same now, and it can run as I wished.

Thanks a lot for you help. ^.^

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.