Cargo build for Linux compilation errors from Once_cell?
The error you're getting indicates that the standard library can't be found. When cross-compiling from Windows to Linux, it's best to use *-musl
targets, to avoid having to come up with the Linux-specific libraries that *-gnu
targets require. To fix the errors simply run the following command:
rustup target add x86_64-unknown-linux-musl
This will install the relevant stdlib. You will have to do this for each toolchain you intend to cross-compile from (if you want to use both stable and nightly or something).
If you cargo build
at this point, and instead of getting a bunch of compiler errors, you should be getting linker errors instead. To fix this, add the following lines to your .cargo/config.toml
file:
[target.x86_64-unknown-linux-musl]
linker = "rust-lld"
That should be enough to get things built, although some crates may have platform/toolchain requirements that might take some more effort to satisfy.
Of course, that assumes amazon's ec2 instances are actually x86_64 machines, which they may not be. Similar steps should work for other platforms, just using the required target. For example, to build for a 64-bit arm platform you would just use the same steps but with the target aarch64-unknown-linux-musl
, and I use these steps with armv7-unknown-linux-musleabihf
to build stuff for my raspberry pi.
How to cross compile from Mac to Linux?
Rust not having a runtime means that it doesn't have a lot of code running as part of the language (for example a garbage collector or bytecode interpreter). It does still need to use operating system primitives (i.e. syscalls), and these are different on MacOS and Linux.
What you want is a cross compiler. If you're using rustup
, then installing a cross compiler should be simple:
# Install the toolchain to build Linux x86_64 binaries
rustup target add x86_64-unknown-linux-gnu
Then building is:
cargo build --release --target=x86_64-unknown-linux-gnu
Caveat: I don't have an OS X machine to test this on; please comment or edit to fix this if it works!
Compling Rust on Mac M1 for target x86_64 linux
It looks like the executable is actually named x86_64-linux-gnu-gcc
, see https://packages.debian.org/bullseye/arm64/gcc-x86-64-linux-gnu/filelist.
Related Topics
Can a Program Read Its Own Elf Section
Linux Async (Io_Submit) Write V/S Normal (Buffered) Write
How to Use Sed to Delete Leading Digits
Linux - Create Animated Gif with Pan and Zoom
Difference Between Different Ways of Running Shell Script
Install Sqlite3 Dev and Other Packages in Centos
How to Test My Bash Script on Older Versions of Bash
Bash: Getting Percentage from a Frequency Table
Base Address at Which The Linux Kernel Is Loaded
How to Execute an Arbitrary Script with a Working Directory of The Directory Its In
Dynamic Listening Ports Inside Docker Container
How Does Ltrace (Library Tracing Tool) Work
/Usr/Local/Ssl/Lib/Libcrypto.A: Could Not Read Symbols: Bad Value
Change a String in a File with Sed
Cron Expression to Run on Different Days for Different Months
Does Grub Switch to Protected Mode