Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Cross compile macOS -> Linux server... really need docker?
Cross compile macOS -> Linux server... really need docker?
โ Rust ๐ 2025-08-30 ๐ค surdeus ๐๏ธ 2I was able to cross compile from my laptop (macOS) to iOS and Android devices without much problem. I just used the usual cargo build
but with a different --target
argument. But for some reason that doesnโt work with Linux. I want to deploy the binary to my Linux server (x86_64). I tried the following, and it failed:
% cargo build --target x86_64-unknown-linux-gnu -p hello-cross
Compiling hello-cross v0.1.0 (/Users/rob/Workspace/MonoRepo3/learning/hello-cross)
error: linking with `cc` failed: exit status: 1
|
= note: "cc" "-m64" "/var/folders/zm/mzv_wcgn0gn4xcj3z6vl4_cm0000gn/T/rustclPzqtP/symbols.o" "<7 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/var/folders/zm/mzv_wcgn0gn4xcj3z6vl4_cm0000gn/T/rustclPzqtP/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/Users/rob/Workspace/MonoRepo3/target/x86_64-unknown-linux-gnu/debug/deps/hello_cross-5c3b0cdd7be55a39" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: clang: warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]
ld: unknown options: --as-needed -Bstatic -Bdynamic --eh-frame-hdr -z --gc-sections -z -z
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: could not compile `hello-cross` (bin "hello-cross") due to 1 previous error
I thought Rust was based on LLVM and that LLVM would have enough to cross compile binaries without other tools.
Someone recommend cross
. I installed it with cargo. It appears to want docker. I donโt want to have to learn about docker
if I can avoid it, so I wanted to check. Is all this really needed to cross compile to Linux? Why doesnโt a simple cargo build --target ...
work like it did for Android and iOS?
% cross build --target x86_64-unknown-linux-gnu -p hello-cross
ERROR: Cannot connect to the Docker daemon at unix:///Users/rob/.docker/run/docker.sock. Is the docker daemon running?
Error:
0: could not run container
1: when building custom image
2: when pre-building
3: `docker build --label 'org.cross-rs.for-cross-target=x86_64-unknown-linux-gnu' --label 'org.cross-rs.workspace_root=/Users/rob/Workspace/MonoRepo3' --tag cross-custom-monorepo:x86_64-unknown-linux-gnu-8a8d0-pre-build --build-arg 'CROSS_CMD=dpkg --add-architecture $CROSS_DEB_ARCH
apt-get update && apt-get install --assume-yes libssl-dev:$CROSS_DEB_ARCH' --build-arg 'CROSS_DEB_ARCH=amd64' --file /Users/rob/Workspace/MonoRepo3/target/x86_64-unknown-linux-gnu/Dockerfile.x86_64-unknown-linux-gnu-custom /Users/rob/Workspace/MonoRepo3` failed with exit status: 1
Note: CROSS_CMD=dpkg --add-architecture $CROSS_DEB_ARCH
apt-get update && apt-get install --assume-yes libssl-dev:$CROSS_DEB_ARCH
3 posts - 1 participant
๐ท๏ธ Rust_feed