Skip to content

Cross compile from x86_64-unknown-linux-gnu to aarch64-apple-darwin fails #679

@kcalvinalvin

Description

@kcalvinalvin

I came across this error and wanted to document it here in case it's of help. I was compiling bdk which also compiles secp256k1-sys and when trying to cross-compile to aarch64-apple-darwin from x86_64-unknown-linxu-gnu, compilation fails with gcc: error: unrecognized command-line option ‘-arch’.

This stackoverflow answer suggests that -arch is only for gcc with xcode, which means I wouldn't be able to cross-compile.

Below is the full error log I got:

[I] calvin@bitcoin ~/b/r/r/utreexod (main)> cargo build --release --target=aarch64-apple-darwin                                                                                                                                                                                                              
   Compiling secp256k1-sys v0.8.1                                                                                                                                                                                                                                                                            
   Compiling bip39 v2.0.0                                                                                                                                                                                                                                                                                    
   Compiling weedle2 v4.0.0                                                                                                                                                                                                                                                                                  
   Compiling uniffi v0.25.0                                                                                                                                                                                                                                                                                  
The following warnings were emitted during compilation:                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                             
warning: gcc: error: unrecognized command-line option ‘-arch’                                                                                                                                                                                                                                                
warning: gcc: error: unrecognized command-line option ‘-arch’                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                             
error: failed to run custom build command for `secp256k1-sys v0.8.1`                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                             
Caused by:                                                                                                                                                                                                                                                                                                   
  process didn't exit successfully: `/home/calvin/bitcoin-projects/rust/rustup/utreexod/target/release/build/secp256k1-sys-678d711ae927d0b8/build-script-build` (exit status: 1)                                                                                                                             
  --- stdout                                                                                                                                                                                                                                                                                                 
  TARGET = Some("aarch64-apple-darwin")                                                                                                                                                                                                                                                                      
  OPT_LEVEL = Some("3")                                                                                                                                                                                                                                                                                      
  HOST = Some("x86_64-unknown-linux-gnu")                                                                                                                                                                                                                                                                    
  cargo:rerun-if-env-changed=CC_aarch64-apple-darwin                                                                                                                                                                                                                                                         
  CC_aarch64-apple-darwin = None                                                                                                                                                                                                                                                                             
  cargo:rerun-if-env-changed=CC_aarch64_apple_darwin                                                                                                                                                                                                                                                         
  CC_aarch64_apple_darwin = None                                                                                                                                                                                                                                                                             
  cargo:rerun-if-env-changed=TARGET_CC                                                                                                                                                                                                                                                                       
  TARGET_CC = None                                                                                                                                                                                                                                                                                           
  cargo:rerun-if-env-changed=CC                                                                                                                                                                                                                                                                              
  CC = Some("gcc")                                                                                                                                                                                                                                                                                           
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS                                                                                                                                                                                                                                                            
  CRATE_CC_NO_DEFAULTS = None                                                                                                                                                                                                                                                                                
  DEBUG = Some("false")                                                                                                                                                                                                                                                                                      
  CARGO_CFG_TARGET_FEATURE = Some("aes,crc,dit,dotprod,dpb,dpb2,fcma,fhm,flagm,fp16,frintts,jsconv,lor,lse,neon,paca,pacg,pan,pmuv3,ras,rcpc,rcpc2,rdm,sb,sha2,sha3,ssbs,vh")                                                                                                                                
  cargo:rerun-if-env-changed=CFLAGS_aarch64-apple-darwin                                                                                                                                                                                                                                                     
  CFLAGS_aarch64-apple-darwin = None                                                                                                                                                                                                                                                                         
  cargo:rerun-if-env-changed=CFLAGS_aarch64_apple_darwin                                                                                                                                                                                                                                                     
  CFLAGS_aarch64_apple_darwin = None                                                                                                                                                                                                                                                                         
  cargo:rerun-if-env-changed=TARGET_CFLAGS                                                                                                                                                                                                                                                                   
  TARGET_CFLAGS = None                                                                                                                                                                                                                                                                                       
  cargo:rerun-if-env-changed=CFLAGS                                                                                                                                                                                                                                                                          
  CFLAGS = None                                                                                                                                                                                                                                                                                              
  cargo:rerun-if-env-changed=CC_aarch64-apple-darwin                                                                                                                                                                                                                                                         
  CC_aarch64-apple-darwin = None                                                                                                                                                                                                                                                                             
  cargo:rerun-if-env-changed=CC_aarch64_apple_darwin                                                                                                                                                                                                                                                         
  CC_aarch64_apple_darwin = None                                                                                                                                                                                                                                                                             
  cargo:rerun-if-env-changed=TARGET_CC                                                                                                                                                                                                                                                                       
  TARGET_CC = None                                                                                                                                                                                                                                                                                           
  cargo:rerun-if-env-changed=CC                                                                                                                                                                                                                                                                              
  CC = Some("gcc")                                                                                                                                                                                                                                                                                           
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS                                                                                                                                                                                                                                                            
  CRATE_CC_NO_DEFAULTS = None                                                                                                                                                                                                                                                                                
  CARGO_CFG_TARGET_FEATURE = Some("aes,crc,dit,dotprod,dpb,dpb2,fcma,fhm,flagm,fp16,frintts,jsconv,lor,lse,neon,paca,pacg,pan,pmuv3,ras,rcpc,rcpc2,rdm,sb,sha2,sha3,ssbs,vh")                                                                                                                                
  cargo:rerun-if-env-changed=CFLAGS_aarch64-apple-darwin                                                                                                                                                                                                                                                     
  CFLAGS_aarch64-apple-darwin = None                                                                                                                                                                                                                                                                         
  cargo:rerun-if-env-changed=CFLAGS_aarch64_apple_darwin                                                                                                                                                                                                                                                     
  CFLAGS_aarch64_apple_darwin = None                                                                                                                                                                                                                                                                         
  cargo:rerun-if-env-changed=TARGET_CFLAGS                                                                                                                                                                                                                                                                   
  TARGET_CFLAGS = None                                                                                                                                                                                                                                                                                       
  cargo:rerun-if-env-changed=CFLAGS                                                                                                                                                                                                                                                                          
  CFLAGS = None                                                                                                                                                                                                                                                                                              
  running: "gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-arch" "arm64" "-I" "depend/secp256k1/" "-I" "depend/secp256k1/include" "-I" "depend/secp256k1/src" "-Wall" "-Wextra" "-DSECP256K1_API=" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG=1" "-DENABLE_MODULE_EXTRAKEYS=1" "-DECM
ULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-DENABLE_MODULE_RECOVERY=1" "-o" "/home/calvin/bitcoin-projects/rust/rustup/utreexod/target/aarch64-apple-darwin/release/build/secp256k1-sys-0f08fdb2410250b6/out/depend/secp256k1/contrib/lax_der_parsing.o" "-c" "depe
nd/secp256k1/contrib/lax_der_parsing.c"                                                                                                                                                                                                                                                                      
  cargo:warning=gcc: error: unrecognized command-line option ‘-arch’                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                             
  exit status: 1                                                                                                                                                                                                                                                                                             
  running: "gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-arch" "arm64" "-I" "depend/secp256k1/" "-I" "depend/secp256k1/include" "-I" "depend/secp256k1/src" "-I" "wasm/wasm-sysroot" "-Wall" "-Wextra" "-DSECP256K1_API=" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG=1" "-DENABLE_M
ODULE_EXTRAKEYS=1" "-DECMULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-DENABLE_MODULE_RECOVERY=1" "-o" "/home/calvin/bitcoin-projects/rust/rustup/utreexod/target/aarch64-apple-darwin/release/build/secp256k1-sys-0f08fdb2410250b6/out/depend/secp256k1/contrib/lax_
der_parsing.o" "-c" "depend/secp256k1/contrib/lax_der_parsing.c"                                                                                                                                                                                                                                             
  cargo:warning=gcc: error: unrecognized command-line option ‘-arch’                                                                                                                                                                                                                                         
                                                                                                                                                                                                                                                                                                             
  exit status: 1                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                             
  --- stderr                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                               
                                                                                                                                                                                                                                                                               
  error occurred: Command "gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-arch" "arm64" "-I" "depend/secp256k1/" "-I" "depend/secp256k1/include" "-I" "depend/secp256k1/src" "-I" "wasm/wasm-sysroot" "-Wall" "-Wextra" "-DSECP256K1_API=" "-DENABLE_MODULE_ECDH=1" "-DENABLE_MODULE_SCHNORRSIG
=1" "-DENABLE_MODULE_EXTRAKEYS=1" "-DECMULT_GEN_PREC_BITS=4" "-DECMULT_WINDOW_SIZE=15" "-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1" "-DENABLE_MODULE_RECOVERY=1" "-o" "/home/calvin/bitcoin-projects/rust/rustup/utreexod/target/aarch64-apple-darwin/release/build/secp256k1-sys-0f08fdb2410250b6/out/depend/secp256
k1/contrib/lax_der_parsing.o" "-c" "depend/secp256k1/contrib/lax_der_parsing.c" with args "gcc" did not execute successfully (status code exit status: 1).                       

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions