cross-rs/cross

target armv7 on macOS Silicon fails: linker x86_64-unknown-linux-gnu-gcc unknown

Closed this issue · 7 comments

Checklist

Describe your issue

Trying to cross-compile from macOS to raspi.

the "hello" binary as mentioned in "Getting Started" works. Once I try it on a real project with dependencies I always run into an error as seen below at "example"

Code is from two minor projects of mine: https://github.com/kelko/glitter2 & https://github.com/kelko/html-streaming-editor, as well as a project I can't disclose yet.

I tried target of x86_64-unknown-linux-gnu, but that won't work either (not even for the default hello bin created by cargo).

What target(s) are you cross-compiling for?

armv7-unknown-linux-gnueabihf, armv7-unknown-linux-musleabihf, x86_64-unknown-linux-gnu

Which operating system is the host (e.g computer cross is on) running?

  • macOS
  • Windows
  • Linux / BSD
  • other OS (specify in description)

What architecture is the host?

  • x86_64 / AMD64
  • arm32
  • arm64 (including Mac M1)

What container engine is cross using?

  • docker
  • podman
  • other container engine (specify in description)

cross version

cross 0.2.5 (53a45db 2024-05-11)

Example

cross build --target armv7-unknown-linux-gnueabihf

returns:

Compiling proc-macro2 v1.0.67
error: linker x86_64-unknown-linux-gnu-gcc not found
|
= note: No such file or directory (os error 2)

error: could not compile proc-macro2 (build script) due to 1 previous error

The mentioned lib changes (proc-macro2, log, ...), the rest stays.

Additional information / notes

No response

can you post the complete build log including the output when you add -v to the command?

Sure @Emilgardis

cross build --target arm-unknown-linux-gnueabihf -v
+ cargo metadata --format-version 1 --filter-platform arm-unknown-linux-gnueabihf
+ rustc --print sysroot
+ /usr/local/bin/docker
+ /usr/local/bin/docker version -f '{{ .Server.Os }},,,{{ .Server.Arch }}'
+ /usr/local/bin/docker info -f {{.SecurityOptions}}
+ rustup toolchain list
+ rustup target list --toolchain stable-x86_64-unknown-linux-gnu
+ rustup component list --toolchain stable-x86_64-unknown-linux-gnu
+ /usr/local/bin/docker run --userns host --platform linux/amd64 -e 'XARGO_HOME=/Users/kelko/.xargo' -e 'CARGO_HOME=/Users/kelko/.cargo' -e 'CROSS_RUST_SYSROOT=/Users/kelko/.rustup/toolchains/stable-x86_64-unknown-linux-gnu' -e 'CARGO_TARGET_DIR=/target' -e 'CROSS_RUNNER=' -e TERM -e 'USER=kelko' -e 'CROSS_RUSTC_MAJOR_VERSION=1' -e 'CROSS_RUSTC_MINOR_VERSION=78' -e 'CROSS_RUSTC_PATCH_VERSION=0' --name cross-stable-x86_64-unknown-linux-gnu-5029f-9b00956e5-arm-unknown-linux-gnueabihf-1eeca-1715515797303 --rm --user 501:20 -v /Users/kelko/.xargo:/Users/kelko/.xargo:z -v /Users/kelko/.cargo:/Users/kelko/.cargo:z -v /Users/kelko/.cargo/bin -v /Users/kelko/Developer/rust/glitter:/Users/kelko/Developer/rust/glitter:z -v /Users/kelko/.rustup/toolchains/stable-x86_64-unknown-linux-gnu:/Users/kelko/.rustup/toolchains/stable-x86_64-unknown-linux-gnu:z,ro -v /Users/kelko/Developer/rust/glitter/target:/target:z -w /Users/kelko/Developer/rust/glitter -t ghcr.io/cross-rs/arm-unknown-linux-gnueabihf:main sh -c 'PATH="$PATH":"/Users/kelko/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin" cargo build --target arm-unknown-linux-gnueabihf -v'
   Compiling proc-macro2 v1.0.67
       Fresh unicode-ident v1.0.12
       Fresh heck v0.4.1
   Compiling utf8parse v0.2.1
   Compiling colorchoice v1.0.0
   Compiling anstyle-query v1.0.0
   Compiling anstyle v1.0.3
   Compiling clap_lex v0.6.0
     Running `rustc --crate-name build_script_build --edition=2021 /Users/kelko/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.67/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=122 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=d4d64827ecbecec8 -C extra-filename=-d4d64827ecbecec8 --out-dir /target/debug/build/proc-macro2-d4d64827ecbecec8 -C linker=x86_64-unknown-linux-gnu-gcc -L dependency=/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name utf8parse --edition=2018 /Users/kelko/.cargo/registry/src/index.crates.io-6f17d22bba15001f/utf8parse-0.2.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=122 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="default"' -C metadata=21e7c44e7c8f9a1f -C extra-filename=-21e7c44e7c8f9a1f --out-dir /target/arm-unknown-linux-gnueabihf/debug/deps --target arm-unknown-linux-gnueabihf -C linker=arm-unknown-linux-gnueabihf-gcc -L dependency=/target/arm-unknown-linux-gnueabihf/debug/deps -L dependency=/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name colorchoice --edition=2021 /Users/kelko/.cargo/registry/src/index.crates.io-6f17d22bba15001f/colorchoice-1.0.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=122 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=fed733e586d77a18 -C extra-filename=-fed733e586d77a18 --out-dir /target/arm-unknown-linux-gnueabihf/debug/deps --target arm-unknown-linux-gnueabihf -C linker=arm-unknown-linux-gnueabihf-gcc -L dependency=/target/arm-unknown-linux-gnueabihf/debug/deps -L dependency=/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name anstyle_query --edition=2021 /Users/kelko/.cargo/registry/src/index.crates.io-6f17d22bba15001f/anstyle-query-1.0.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=122 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=79ad412c5c7100f9 -C extra-filename=-79ad412c5c7100f9 --out-dir /target/arm-unknown-linux-gnueabihf/debug/deps --target arm-unknown-linux-gnueabihf -C linker=arm-unknown-linux-gnueabihf-gcc -L dependency=/target/arm-unknown-linux-gnueabihf/debug/deps -L dependency=/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name anstyle --edition=2021 /Users/kelko/.cargo/registry/src/index.crates.io-6f17d22bba15001f/anstyle-1.0.3/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=122 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=755d8b081e05ff32 -C extra-filename=-755d8b081e05ff32 --out-dir /target/arm-unknown-linux-gnueabihf/debug/deps --target arm-unknown-linux-gnueabihf -C linker=arm-unknown-linux-gnueabihf-gcc -L dependency=/target/arm-unknown-linux-gnueabihf/debug/deps -L dependency=/target/debug/deps --cap-lints allow`
   Compiling strsim v0.10.0
   Compiling linked-hash-map v0.5.6
     Running `rustc --crate-name clap_lex --edition=2021 /Users/kelko/.cargo/registry/src/index.crates.io-6f17d22bba15001f/clap_lex-0.6.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=122 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=6d8fa6d12ac6c458 -C extra-filename=-6d8fa6d12ac6c458 --out-dir /target/arm-unknown-linux-gnueabihf/debug/deps --target arm-unknown-linux-gnueabihf -C linker=arm-unknown-linux-gnueabihf-gcc -L dependency=/target/arm-unknown-linux-gnueabihf/debug/deps -L dependency=/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name strsim --edition=2015 /Users/kelko/.cargo/registry/src/index.crates.io-6f17d22bba15001f/strsim-0.10.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=122 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=47bd2a8585912290 -C extra-filename=-47bd2a8585912290 --out-dir /target/arm-unknown-linux-gnueabihf/debug/deps --target arm-unknown-linux-gnueabihf -C linker=arm-unknown-linux-gnueabihf-gcc -L dependency=/target/arm-unknown-linux-gnueabihf/debug/deps -L dependency=/target/debug/deps --cap-lints allow`
     Running `rustc --crate-name linked_hash_map --edition=2015 /Users/kelko/.cargo/registry/src/index.crates.io-6f17d22bba15001f/linked-hash-map-0.5.6/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=122 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=a4de62d126640ce1 -C extra-filename=-a4de62d126640ce1 --out-dir /target/arm-unknown-linux-gnueabihf/debug/deps --target arm-unknown-linux-gnueabihf -C linker=arm-unknown-linux-gnueabihf-gcc -L dependency=/target/arm-unknown-linux-gnueabihf/debug/deps -L dependency=/target/debug/deps --cap-lints allow`
   Compiling anstyle-parse v0.2.1
     Running `rustc --crate-name anstyle_parse --edition=2021 /Users/kelko/.cargo/registry/src/index.crates.io-6f17d22bba15001f/anstyle-parse-0.2.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=122 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="utf8"' -C metadata=0ee34a9d5356aedc -C extra-filename=-0ee34a9d5356aedc --out-dir /target/arm-unknown-linux-gnueabihf/debug/deps --target arm-unknown-linux-gnueabihf -C linker=arm-unknown-linux-gnueabihf-gcc -L dependency=/target/arm-unknown-linux-gnueabihf/debug/deps -L dependency=/target/debug/deps --extern utf8parse=/target/arm-unknown-linux-gnueabihf/debug/deps/libutf8parse-21e7c44e7c8f9a1f.rmeta --cap-lints allow`
   Compiling exitcode v1.1.2
     Running `rustc --crate-name exitcode --edition=2015 /Users/kelko/.cargo/registry/src/index.crates.io-6f17d22bba15001f/exitcode-1.1.2/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=122 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=14c7d777b932521e -C extra-filename=-14c7d777b932521e --out-dir /target/arm-unknown-linux-gnueabihf/debug/deps --target arm-unknown-linux-gnueabihf -C linker=arm-unknown-linux-gnueabihf-gcc -L dependency=/target/arm-unknown-linux-gnueabihf/debug/deps -L dependency=/target/debug/deps --cap-lints allow`
   Compiling yaml-rust v0.4.5
     Running `rustc --crate-name yaml_rust --edition=2018 /Users/kelko/.cargo/registry/src/index.crates.io-6f17d22bba15001f/yaml-rust-0.4.5/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=122 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=46716e2cfc8ae46b -C extra-filename=-46716e2cfc8ae46b --out-dir /target/arm-unknown-linux-gnueabihf/debug/deps --target arm-unknown-linux-gnueabihf -C linker=arm-unknown-linux-gnueabihf-gcc -L dependency=/target/arm-unknown-linux-gnueabihf/debug/deps -L dependency=/target/debug/deps --extern linked_hash_map=/target/arm-unknown-linux-gnueabihf/debug/deps/liblinked_hash_map-a4de62d126640ce1.rmeta --cap-lints allow`
   Compiling anstream v0.6.4
     Running `rustc --crate-name anstream --edition=2021 /Users/kelko/.cargo/registry/src/index.crates.io-6f17d22bba15001f/anstream-0.6.4/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=122 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="auto"' --cfg 'feature="default"' --cfg 'feature="wincon"' -C metadata=51f6c03643308579 -C extra-filename=-51f6c03643308579 --out-dir /target/arm-unknown-linux-gnueabihf/debug/deps --target arm-unknown-linux-gnueabihf -C linker=arm-unknown-linux-gnueabihf-gcc -L dependency=/target/arm-unknown-linux-gnueabihf/debug/deps -L dependency=/target/debug/deps --extern anstyle=/target/arm-unknown-linux-gnueabihf/debug/deps/libanstyle-755d8b081e05ff32.rmeta --extern anstyle_parse=/target/arm-unknown-linux-gnueabihf/debug/deps/libanstyle_parse-0ee34a9d5356aedc.rmeta --extern anstyle_query=/target/arm-unknown-linux-gnueabihf/debug/deps/libanstyle_query-79ad412c5c7100f9.rmeta --extern colorchoice=/target/arm-unknown-linux-gnueabihf/debug/deps/libcolorchoice-fed733e586d77a18.rmeta --extern utf8parse=/target/arm-unknown-linux-gnueabihf/debug/deps/libutf8parse-21e7c44e7c8f9a1f.rmeta --cap-lints allow`
error: linker `x86_64-unknown-linux-gnu-gcc` not found
  |
  = note: No such file or directory (os error 2)

error: could not compile `proc-macro2` (build script) due to 1 previous error

Caused by:
  process didn't exit successfully: `rustc --crate-name build_script_build --edition=2021 /Users/kelko/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.67/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=122 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="proc-macro"' -C metadata=d4d64827ecbecec8 -C extra-filename=-d4d64827ecbecec8 --out-dir /target/debug/build/proc-macro2-d4d64827ecbecec8 -C linker=x86_64-unknown-linux-gnu-gcc -L dependency=/target/debug/deps --cap-lints allow` (exit status: 1)
warning: build failed, waiting for other jobs to finish...
+ rustup component list --toolchain stable-x86_64-unknown-linux-gnu

I'm unable to reproduce this on my M1 macbook. glitter2 compiles without issue with cross build --target arm-unknown-linux-gnueabihf -v

can you try cargo clean

if that doesn't solve it, can you share the output of

docker info

also, try docker pull ghcr.io/cross-rs/arm-unknown-linux-gnueabihf:main

Is the description correct? Does it fail on targets armv7-unknown-linux-gnueabihf, armv7-unknown-linux-musleabihf, x86_64-unknown-linux-gnu? Because the command you shared is for arm-unknown-linux-gnueabihf.

I ran cargo clean and same behaviour. And yes, I tried multiple targets, all with the same result. But it seems I forgot to also check arm-unknown-linux-gnueabihf, which I used for the verbose output.

The requested docker info (freshly installed docker, just minutes before trying cross):

docker info
Client:
 Version:    26.0.0
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.13.1-desktop.1
    Path:     /Users/kelko/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.26.1-desktop.1
    Path:     /Users/kelko/.docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container. (Docker Inc.)
    Version:  0.0.27
    Path:     /Users/kelko/.docker/cli-plugins/docker-debug
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.2
    Path:     /Users/kelko/.docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.23
    Path:     /Users/kelko/.docker/cli-plugins/docker-extension
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.4
    Path:     /Users/kelko/.docker/cli-plugins/docker-feedback
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.1.0
    Path:     /Users/kelko/.docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /Users/kelko/.docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.6.3
    Path:     /Users/kelko/.docker/cli-plugins/docker-scout

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 6
 Server Version: 26.0.0
 Storage Driver: overlayfs
  driver-type: io.containerd.snapshotter.v1
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
  cgroupns
 Kernel Version: 6.6.22-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 8
 Total Memory: 7.657GiB
 Name: docker-desktop
 ID: 8b3416c5-6baa-4bc6-acc1-50096f973251
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=unix:///Users/kelko/Library/Containers/com.docker.docker/Data/docker-cli.sock
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: daemon is not using the default seccomp profile

pulling the mentioned docker image resulted in strange message:

docker pull ghcr.io/cross-rs/arm-unknown-linux-gnueabihf:main
Error response from daemon: no match for platform in manifest: not found

Same for armv7-unknown-linux-gnueabihf and armv7-unknown-linux-musleabihf

oops sorry, you need to add --platform amd64

docker pull ghcr.io/cross-rs/arm-unknown-linux-gnueabihf:main --platform amd64
main: Pulling from cross-rs/arm-unknown-linux-gnueabihf
Digest: sha256:7391604df9b188f157166b2fff2774cf0c45797137214a5848489ca0c8dbccba
Status: Image is up to date for ghcr.io/cross-rs/arm-unknown-linux-gnueabihf:main
ghcr.io/cross-rs/arm-unknown-linux-gnueabihf:main

What's Next?
  View a summary of image vulnerabilities and recommendations → docker scout quickview ghcr.io/cross-rs/arm-unknown-linux-gnueabihf:main

I'm unable to reproduce this on my M1 macbook. glitter2 compiles without issue

Just for me to understand it better:
Do I need to install first some additional toolchain or targets on my local Mac? Or are all the toolchains added & run in the container?

I found the culprit. Before trying cross I had toolchains & targets in place to cross-compile to linux & windows.
I forgot that this also included some configuration in ~/.cargo/config.toml. I removed said configs and now it all works.

Sorry for the inconvenience