Cross compiling from Ubuntu WSL to Raspberry Pi Musl

I'm trying to cross compile from WSL Ubuntu to my Raspberry Pi 3 target

armv7-unknown-linux-musleabihf

For reasons I don't want to use Docker or use the gnueabihf target (which I already have working)

I've installed gcc-arm-linux-gnueabihf, and I'm running the below command to build. Note that I've run this same thing on Manjaro before and it worked, and it also works fine if I swap out musleabihf with gnueabihf

CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER=arm-linux-gnueabihf-gcc CC_armv7_unknown_linux_musleabihf=arm-linux-gnueabihf-gcc cargo build --target armv7-unknown-linux-musleabihf --release

The error I get is

error: linking with `arm-linux-gnueabihf-gcc` failed: exit status: 1
  |
  = note: "arm-linux-gnueabihf-gcc" "/home/zireael9797/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-musleabihf/lib/self-contained/crt1.o" "/home/zireael9797/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-musleabihf/lib/self-contained/crti.o" "/home/zireael9797/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-musleabihf/lib/self-contained/crtbegin.o" "/mnt/d/Repos/Rust/demo_project/target/armv7-unknown-linux-musleabihf/release/deps/demo_project-31909ae0ce990567.demo_project.63217f5f-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "/mnt/d/Repos/Rust/demo_project/target/armv7-unknown-linux-musleabihf/release/deps" "-L" "/mnt/d/Repos/Rust/demo_project/target/release/deps" "-L" "/mnt/d/Repos/Rust/demo_project/target/armv7-unknown-linux-musleabihf/release/build/ring-b0a4f8b326ff2cba/out" "-L" "/mnt/d/Repos/Rust/demo_project/target/armv7-unknown-linux-musleabihf/release/build/openssl-sys-d00f826df67789e2/out/openssl-build/install/lib" "-L" "/home/zireael9797/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-musleabihf/lib" "-Wl,-Bstatic" "/tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib" "/tmp/rustcyf9YCG/libring-79a71dd09185c4d3.rlib" "-Wl,--start-group" "/tmp/rustcyf9YCG/libunwind-c43f2d8f6e7ee092.rlib" "/tmp/rustcyf9YCG/liblibc-faedc50e2d768525.rlib" "-Wl,--end-group" "/home/zireael9797/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-musleabihf/lib/libcompiler_builtins-d6a690a2b68d1216.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-nostartfiles" "-L" "/home/zireael9797/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-musleabihf/lib" "-L" "/home/zireael9797/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-musleabihf/lib/self-contained" "-o" "/mnt/d/Repos/Rust/demo_project/target/armv7-unknown-linux-musleabihf/release/deps/demo_project-31909ae0ce990567" "-Wl,--gc-sections" "-static" "-no-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs" "/home/zireael9797/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-musleabihf/lib/self-contained/crtend.o" "/home/zireael9797/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/armv7-unknown-linux-musleabihf/lib/self-contained/crtn.o"
  = note: /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(armcap.o): in function `ill_handler':
          armcap.c:(.text.ill_handler+0x8): undefined reference to `__longjmp_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(ssl3_record_tls13.o): in function `tls13_enc':
          ssl3_record_tls13.c:(.text.tls13_enc+0x86): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(s3_cbc.o): in function `ssl3_cbc_digest_record':
          s3_cbc.c:(.text.ssl3_cbc_digest_record+0x190): undefined reference to `__memset_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: s3_cbc.c:(.text.ssl3_cbc_digest_record+0x1de): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: s3_cbc.c:(.text.ssl3_cbc_digest_record+0x4fc): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: s3_cbc.c:(.text.ssl3_cbc_digest_record+0x5f6): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(ssl_ciph.o): in function `ciphersuite_cb':
          ssl_ciph.c:(.text.ciphersuite_cb+0x26): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(ssl_lib.o): in function `ssl_session_hash':
          ssl_lib.c:(.text.ssl_session_hash+0x44): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(ssl_lib.o): in function `nss_keylog_int.part.0':
          ssl_lib.c:(.text.nss_keylog_int.part.0+0x6c): undefined reference to `__sprintf_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: ssl_lib.c:(.text.nss_keylog_int.part.0+0xaa): undefined reference to `__sprintf_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(ssl_lib.o): in function `SSL_has_matching_session_id':
          ssl_lib.c:(.text.SSL_has_matching_session_id+0x2e): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(ssl_sess.o): in function `lookup_sess_in_cache':
          ssl_sess.c:(.text.lookup_sess_in_cache+0x40): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(t1_lib.o): in function `nid_cb':
          t1_lib.c:(.text.nid_cb+0x52): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(t1_lib.o): in function `sig_cb':
          t1_lib.c:(.text.sig_cb+0x64): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(eck_prn.o): in function `ECPKParameters_print':
          eck_prn.c:(.text.ECPKParameters_print+0x300): undefined reference to `__memset_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: eck_prn.c:(.text.ECPKParameters_print+0x37e): undefined reference to `__memset_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(e_rc4_hmac_md5.o): in function `rc4_hmac_md5_ctrl':
          e_rc4_hmac_md5.c:(.text.rc4_hmac_md5_ctrl+0x4a): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(hmac.o): in function `HMAC_Init_ex':
          hmac.c:(.text.HMAC_Init_ex+0x66): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(ocb128.o): in function `CRYPTO_ocb128_aad':
          ocb128.c:(.text.CRYPTO_ocb128_aad+0x1b2): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(ocb128.o): in function `CRYPTO_ocb128_encrypt':
          ocb128.c:(.text.CRYPTO_ocb128_encrypt+0x25c): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(ocb128.o): in function `CRYPTO_ocb128_decrypt':
          ocb128.c:(.text.CRYPTO_ocb128_decrypt+0x262): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(rand_unix.o): in function `wait_random_seeded':
          rand_unix.c:(.text.wait_random_seeded+0x106): undefined reference to `__fdelt_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(cryptlib.o): in function `OPENSSL_showfatal':
          cryptlib.c:(.text.OPENSSL_showfatal+0x2a): undefined reference to `__vfprintf_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(dsa_gen.o): in function `dsa_builtin_paramgen':
          dsa_gen.c:(.text.dsa_builtin_paramgen+0x6c): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: dsa_gen.c:(.text.dsa_builtin_paramgen+0x172): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: dsa_gen.c:(.text.dsa_builtin_paramgen+0x180): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(p5_crpt.o): in function `PKCS5_PBE_keyivgen':
          p5_crpt.c:(.text.PKCS5_PBE_keyivgen+0x1c6): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: p5_crpt.c:(.text.PKCS5_PBE_keyivgen+0x1d6): undefined reference to `__memcpy_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(ui_openssl.o): in function `read_string':
          ui_openssl.c:(.text.read_string+0x38): undefined reference to `__fprintf_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/rustcyf9YCG/libopenssl_sys-f50fe9c5bebd725f.rlib(v3_alt.o): in function `i2v_GENERAL_NAME':
          v3_alt.c:(.text.i2v_GENERAL_NAME+0x10a): undefined reference to `__strcat_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: v3_alt.c:(.text.i2v_GENERAL_NAME+0x116): undefined reference to `__strcat_chk'
          /usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: v3_alt.c:(.text.i2v_GENERAL_NAME+0x134): undefined reference to `__strcat_chk'
          collect2: error: ld returned 1 exit status

  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

warning: `demo_project` (bin "demo_project") generated 20 warnings
error: could not compile `demo_project` due to previous error; 20 warnings emitted
make: *** [makefile:3: arm-musl-release] Error 101

Any guidance would be appreciated

Why are you compiling and linking with arm-linux-gnueabihf? Any C code that you build this way will expect to be linked against the GNU libc, which you obviously don't want and causes all the undefined symbol errors. You have to use the correct toolchain.

If your distro doesn't provide one, you'll either have to find a prebuilt one online or use a tool like crosstool-ng or buildroot to generate one yourself.

Well my distro is plain old ubuntu. I'm not really very knowledgeable in this area. Which would be the correct one for ubuntu?

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.