Cross compiling from Linux to Windows


#1

Hi! I need some help with cross-compiling from windows to linux. I want to be able to cross compile program, that able to call some winapi functions.

My host system is Ubuntu 14.04

My host system is Ubuntu 14.04
uname -a
Linux 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
I have specified linker and ar
`~/.cargo/config`
    [target.i686-pc-windows-gnu]
    linker = "i686-w64-mingw32-gcc"
    ar = "i686-w64-mingw32-gcc-ar"

However I’m not able to compile helloworld with rustup i686-pc-windows-gnu std

cargo build --target=i686-pc-windows-gnu --verbose
cargo build --target=i686-pc-windows-gnu --verbose
warning: unused manifest key: profile.all
   Compiling wincrs v0.1.0 (file:///home/user/Projects/Test/Rust/wincrs)
     Running `rustc --crate-name wincrs src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=9cea176b8240c8f7 -C extra-filename=-9cea176b8240c8f7 --out-dir /home/user/Projects/Test/Rust/wincrs/target/i686-pc-windows-gnu/debug/deps --target i686-pc-windows-gnu -C ar=i686-w64-mingw32-gcc-ar -C linker=i686-w64-mingw32-gcc -L dependency=/home/user/Projects/Test/Rust/wincrs/target/i686-pc-windows-gnu/debug/deps -L dependency=/home/user/Projects/Test/Rust/wincrs/target/debug/deps`
error: linking with `i686-w64-mingw32-gcc` failed: exit code: 1
  |
  = note: "i686-w64-mingw32-gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-Wl,--large-address-aware" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/crt2.o" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o" "-L" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib" "/home/user/Projects/Test/Rust/wincrs/target/i686-pc-windows-gnu/debug/deps/wincrs-9cea176b8240c8f7.wincrs0.rust-cgu.o" "/home/user/Projects/Test/Rust/wincrs/target/i686-pc-windows-gnu/debug/deps/wincrs-9cea176b8240c8f7.wincrs1.rust-cgu.o" "-o" "/home/user/Projects/Test/Rust/wincrs/target/i686-pc-windows-gnu/debug/deps/wincrs-9cea176b8240c8f7.exe" "/home/user/Projects/Test/Rust/wincrs/target/i686-pc-windows-gnu/debug/deps/wincrs-9cea176b8240c8f7.crate.allocator.rust-cgu.o" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "/home/user/Projects/Test/Rust/wincrs/target/i686-pc-windows-gnu/debug/deps" "-L" "/home/user/Projects/Test/Rust/wincrs/target/debug/deps" "-L" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib" "-Wl,-Bstatic" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libstd-1c305b9fc226a713.rlib" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/liballoc_system-1c9a8069829c288b.rlib" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/librand-bb022198b1e571cd.rlib" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libpanic_unwind-bfdcab4022ce49cc.rlib" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/liballoc-901e09c895901b2e.rlib" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libstd_unicode-7913fbc21c7a371d.rlib" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libunwind-5ed3e7f7fa314ca2.rlib" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/liblibc-c3ea8c20bfb99023.rlib" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libcore-86be884ab00afc95.rlib" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libcompiler_builtins-aa9363e0737a80f8.rlib" "-Wl,-Bdynamic" "-l" "advapi32" "-l" "ws2_32" "-l" "userenv" "-l" "shell32" "-Wl,-Bstatic" "-l" "gcc_eh" "-l" "pthread" "-Wl,-Bdynamic" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "/home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/rsend.o"
  = note: /home/user/Projects/Test/Rust/wincrs/target/i686-pc-windows-gnu/debug/deps/wincrs-9cea176b8240c8f7.wincrs0.rust-cgu.o: In function `ZN6wincrs4mainE':
          /home/user/Projects/Test/Rust/wincrs/src/main.rs:2: undefined reference to `std::io::stdio::_print::h0288bf44509655c5'
          /home/user/Projects/Test/Rust/wincrs/target/i686-pc-windows-gnu/debug/deps/wincrs-9cea176b8240c8f7.wincrs0.rust-cgu.o:/home/user/Projects/Test/Rust/wincrs/src/main.rs:(.text+0x8f): undefined reference to `std::rt::lang_start::h531a6dc423adca0b'
          /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libpanic_unwind-bfdcab4022ce49cc.rlib(panic_unwind-bfdcab4022ce49cc.panic_unwind0.rust-cgu.o): In function `ZN12panic_unwind3imp21rust_eh_unwind_resumeE':
          C:\projects\rust/src\libpanic_unwind/gcc.rs:291: undefined reference to `_Unwind_Resume'
          C:\projects\rust/src\libpanic_unwind/gcc.rs:291: undefined reference to `_Unwind_Resume'
          C:\projects\rust/src\libpanic_unwind/gcc.rs:291: undefined reference to `_Unwind_Resume'
          C:\projects\rust/src\libpanic_unwind/gcc.rs:291: undefined reference to `_Unwind_Resume'
          C:\projects\rust/src\libpanic_unwind/gcc.rs:291: undefined reference to `_Unwind_Resume'
          /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libpanic_unwind-bfdcab4022ce49cc.rlib(panic_unwind-bfdcab4022ce49cc.panic_unwind0.rust-cgu.o):C:\projects\rust/src\libpanic_unwind/gcc.rs:291: more undefined references to `_Unwind_Resume' follow
          /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libpanic_unwind-bfdcab4022ce49cc.rlib(panic_unwind-bfdcab4022ce49cc.panic_unwind0.rust-cgu.o): In function `ZN12panic_unwind3imp5panicE':
          C:\projects\rust/src\libpanic_unwind/gcc.rs:83: undefined reference to `_Unwind_RaiseException'
          /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libpanic_unwind-bfdcab4022ce49cc.rlib(panic_unwind-bfdcab4022ce49cc.panic_unwind0.rust-cgu.o): In function `ZN12panic_unwind3imp21rust_eh_unwind_resumeE':
          C:\projects\rust/src\libpanic_unwind/gcc.rs:291: undefined reference to `_Unwind_Resume'
          collect2: error: ld returned 1 exit status
          
error: aborting due to previous error
i686-w64-mingw32-gcc -v
Using built-in specs.
COLLECT_GCC=i686-w64-mingw32-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.8/lto-wrapper
Target: i686-w64-mingw32
Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/include' --mandir='/usr/share/man' --infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var --libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode --disable-dependency-tracking --prefix=/usr --enable-shared --enable-static --disable-multilib --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib --enable-libstdcxx-time=yes --with-tune=generic --enable-version-specific-runtime-libs --enable-threads=posix --enable-fully-dynamic-string --enable-sjlj-exceptions --enable-libgomp --enable-languages=c,c++,fortran,objc,obj-c++ --enable-lto --with-plugin-ld --target=i686-w64-mingw32 --with-gxx-include-dir=/usr/include/c++/4.8 --with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld
Thread model: posix
gcc version 4.8.2 (GCC) 

It seems that it’s related to my (old) cross compiler version.
So I’ve tried to use xargo for cross-compiling.

During this process I’ve met some facts.

Project's Cargo.toml
[package]
name = "wincrs"
version = "0.1.0"

[profile.all]
panic = 'abort'
Project's Xargo.toml

[target.i686-pc-windows-gnu.dependencies.std]

  1. When I’ve tried to compile with panic strategy ‘abort’ (at least there are no warnings that option [profile.all] panic=‘abort’ unused) I’ve got an error:
xargo build --target=i686-pc-windows-gnu --verbose
+ "rustc" "--print" "sysroot"
+ "rustc" "--print" "target-list"
+ RUSTFLAGS="--sysroot /home/user/.xargo -Z force-unstable-if-unmarked"
+ "cargo" "build" "--release" "--manifest-path" "/tmp/xargo.HPt0a5G0NyqO/Cargo.toml" "--target" "i686-pc-windows-gnu" "-v" "-p" "std"
   Compiling core v0.0.0 (file:///home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore)
   Compiling cc v1.0.1
   Compiling libc v0.2.31
   Compiling unwind v0.0.0 (file:///home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libunwind)
    ...
   Compiling filetime v0.1.12
    ...
   Compiling build_helper v0.1.0 (file:///home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/build_helper)
    ...
   Compiling std v0.0.0 (file:///home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd)
    ...
   Compiling compiler_builtins v0.0.0 (file:///home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/rustc/compiler_builtins_shim)
    ...
   Compiling std_unicode v0.0.0 (file:///home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd_unicode)
   Compiling libc v0.0.0 (file:///home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/rustc/libc_shim)
   Compiling rand v0.0.0 (file:///home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/librand)
    ...
   Compiling panic_abort v0.0.0 (file:///home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libpanic_abort)
     Running `rustc --crate-name panic_abort /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libpanic_abort/lib.rs --crate-type lib --emit=dep-info,link -C opt-level=3 -C metadata=d750cad1b0412367 -C extra-filename=-d750cad1b0412367 --out-dir /tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps --target i686-pc-windows-gnu -C ar=i686-w64-mingw32-gcc-ar -C linker=i686-w64-mingw32-gcc -L dependency=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps -L dependency=/tmp/xargo.HPt0a5G0NyqO/target/release/deps --extern core=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/libcore-c72772e3745bb43f.rlib --extern libc=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/liblibc-a4559aada66ce046.rlib --sysroot /home/user/.xargo -Z force-unstable-if-unmarked`
   Compiling alloc v0.0.0 (file:///home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/liballoc)
    ...
   Compiling collections v0.0.0 (file:///home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcollections)
   Compiling alloc_system v0.0.0 (file:///home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/liballoc_system)
     Running `rustc --crate-name collections /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcollections/lib.rs --crate-type lib --emit=dep-info,link -C opt-level=3 -C metadata=6f9512be04f9293e -C extra-filename=-6f9512be04f9293e --out-dir /tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps --target i686-pc-windows-gnu -C ar=i686-w64-mingw32-gcc-ar -C linker=i686-w64-mingw32-gcc -L dependency=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps -L dependency=/tmp/xargo.HPt0a5G0NyqO/target/release/deps --extern core=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/libcore-c72772e3745bb43f.rlib --extern alloc=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/liballoc-83c0e27e7d333b11.rlib --sysroot /home/user/.xargo -Z force-unstable-if-unmarked`
     Running `rustc --crate-name alloc_system /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/liballoc_system/lib.rs --crate-type lib --emit=dep-info,link -C opt-level=3 -C metadata=7cde5ec6df66afe2 -C extra-filename=-7cde5ec6df66afe2 --out-dir /tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps --target i686-pc-windows-gnu -C ar=i686-w64-mingw32-gcc-ar -C linker=i686-w64-mingw32-gcc -L dependency=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps -L dependency=/tmp/xargo.HPt0a5G0NyqO/target/release/deps --extern core=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/libcore-c72772e3745bb43f.rlib --extern libc=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/liblibc-a4559aada66ce046.rlib --extern alloc=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/liballoc-83c0e27e7d333b11.rlib --sysroot /home/user/.xargo -Z force-unstable-if-unmarked`
     Running `rustc --crate-name std /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/lib.rs --crate-type dylib --crate-type rlib --emit=dep-info,link -C prefer-dynamic -C opt-level=3 -C metadata=f4b13a0993731646 --out-dir /tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps --target i686-pc-windows-gnu -C ar=i686-w64-mingw32-gcc-ar -C linker=i686-w64-mingw32-gcc -L dependency=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps -L dependency=/tmp/xargo.HPt0a5G0NyqO/target/release/deps --extern unwind=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/libunwind-e85f997cae22196f.rlib --extern core=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/libcore-c72772e3745bb43f.rlib --extern std_unicode=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/libstd_unicode-9d2e1eff57d7682c.rlib --extern alloc_system=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/liballoc_system-7cde5ec6df66afe2.rlib --extern panic_abort=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/libpanic_abort-d750cad1b0412367.rlib --extern rand=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/librand-6ce8e664a2bf0ed0.rlib --extern collections=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/libcollections-6f9512be04f9293e.rlib --extern compiler_builtins=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/libcompiler_builtins-3ced47ce8ffdf638.rlib --extern alloc=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/liballoc-83c0e27e7d333b11.rlib --extern libc=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/deps/liblibc-a4559aada66ce046.rlib --sysroot /home/user/.xargo -Z force-unstable-if-unmarked -l advapi32 -l ws2_32 -l userenv -l shell32 -L native=/tmp/xargo.HPt0a5G0NyqO/target/i686-pc-windows-gnu/release/build/compiler_builtins-4d46fa57a08b38bf/out`
error[E0463]: can't find crate for `panic_unwind`

error: aborting due to previous error

error: Could not compile `std`.

So the first question is why std depends on panic_unwind even if chosen panic strategy is abort? What I’ve missed?

  1. I’ve been able to avoid this error by adding features = ["panic-unwind"] to Xargo.toml and remove !#[deny(warnings)] from lib.rs of std crate (There are some unused statements, that described below, inside a spoiler). But that leads me to next error:
Warnings
warning: constant item is never used: `PROCESS_QUERY_INFORMATION`
    --> /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/sys/windows/c.rs:1235:5
     |
1235 |     pub const PROCESS_QUERY_INFORMATION: DWORD = 0x0400;
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: #[warn(dead_code)] on by default

warning: constant item is never used: `CP_ACP`
    --> /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/sys/windows/c.rs:1237:5
     |
1237 |     pub const CP_ACP: UINT = 0;
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: constant item is never used: `WC_NO_BEST_FIT_CHARS`
    --> /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/sys/windows/c.rs:1239:5
     |
1239 |     pub const WC_NO_BEST_FIT_CHARS: DWORD = 0x00000400;
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: foreign function is never used: `OpenProcess`
    --> /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/sys/windows/c.rs:1242:9
     |
1242 | /         pub fn OpenProcess(dwDesiredAccess: DWORD,
1243 | |                            bInheritHandle: BOOL,
1244 | |                            dwProcessId: DWORD) -> HANDLE;
     | |_________________________________________________________^

warning: function is never used: `QueryFullProcessImageNameW`
    --> /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/sys/windows/compat.rs:56:9
     |
56   |           pub unsafe fn $symbol($($argname: $argtype),*) -> $rettype {
     |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     | 
    ::: /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/sys/windows/c.rs
     |
1247 | /     compat_fn! {
1248 | |         kernel32:
1249 | |
1250 | |         pub fn QueryFullProcessImageNameW(_hProcess: HANDLE,
...    |
1255 | |         }
1256 | |     }
     | |_____- in this macro invocation
[/details]

[details="i686-w64-mingw32-gcc: error: /home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib/dllcrt2.o: No such file or directory ... etc"]
error: linking with `i686-w64-mingw32-gcc` failed: exit code: 1
  |
  = note: "i686-w64-mingw32-gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-Wl,--large-address-aware" "/home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib/dllcrt2.o" "/home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o" "-L" "/home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib" "/tmp/xargo.QY0kDly5zQlB/target/i686-pc-windows-gnu/release/deps/std.std0.rust-cgu.o" "-o" "/tmp/xargo.QY0kDly5zQlB/target/i686-pc-windows-gnu/release/deps/std.dll" "/tmp/xargo.QY0kDly5zQlB/target/i686-pc-windows-gnu/release/deps/std.crate.metadata.rust-cgu.o" "/tmp/xargo.QY0kDly5zQlB/target/i686-pc-windows-gnu/release/deps/std.crate.allocator.rust-cgu.o" "-nodefaultlibs" "-L" "/tmp/xargo.QY0kDly5zQlB/target/i686-pc-windows-gnu/release/deps" "-L" "/tmp/xargo.QY0kDly5zQlB/target/release/deps" "-L" "/tmp/xargo.QY0kDly5zQlB/target/i686-pc-windows-gnu/release/build/compiler_builtins-4d46fa57a08b38bf/out" "-L" "/home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib" "-l" "advapi32" "-l" "ws2_32" "-l" "userenv" "-l" "shell32" "-Wl,-Bstatic" "-Wl,--whole-archive" "/tmp/rustc.QAv2ygPzZ5ai/libpanic_unwind-662d5a5c86d21e35.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.QAv2ygPzZ5ai/libunwind-e85f997cae22196f.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.QAv2ygPzZ5ai/liblibc-a4559aada66ce046.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.QAv2ygPzZ5ai/librand-6ce8e664a2bf0ed0.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.QAv2ygPzZ5ai/liballoc_system-7cde5ec6df66afe2.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.QAv2ygPzZ5ai/liballoc-83c0e27e7d333b11.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.QAv2ygPzZ5ai/libstd_unicode-9d2e1eff57d7682c.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.QAv2ygPzZ5ai/libcore-c72772e3745bb43f.rlib" "-Wl,--no-whole-archive" "/tmp/rustc.QAv2ygPzZ5ai/libcompiler_builtins-3ced47ce8ffdf638.rlib" "-l" "gcc_eh" "-l" "pthread" "-shared" "-Wl,-Bdynamic" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "/home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib/rsend.o"
  = note: i686-w64-mingw32-gcc: error: /home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib/dllcrt2.o: No such file or directory
          i686-w64-mingw32-gcc: error: /home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o: No such file or directory
          i686-w64-mingw32-gcc: error: /home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib/rsend.o: No such file or directory
          

error: aborting due to previous error

error: Could not compile `std`.
Error
error: linking with `i686-w64-mingw32-gcc` failed: exit code: 1
  |
  = note: "i686-w64-mingw32-gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-Wl,--large-address-aware" "/home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib/dllcrt2.o" "/home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o" "-L" "/home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib" "/tmp/xargo.Xxd8rrsi2qc4/target/i686-pc-windows-gnu/release/deps/std.std0.rust-cgu.o" "-o" "/tmp/xargo.Xxd8rrsi2qc4/target/i686-pc-windows-gnu/release/deps/std.dll" "/tmp/xargo.Xxd8rrsi2qc4/target/i686-pc-windows-gnu/release/deps/std.crate.metadata.rust-cgu.o" "/tmp/xargo.Xxd8rrsi2qc4/target/i686-pc-windows-gnu/release/deps/std.crate.allocator.rust-cgu.o" "-nodefaultlibs" "-L" "/tmp/xargo.Xxd8rrsi2qc4/target/i686-pc-windows-gnu/release/deps" "-L" "/tmp/xargo.Xxd8rrsi2qc4/target/release/deps" "-L" "/tmp/xargo.Xxd8rrsi2qc4/target/i686-pc-windows-gnu/release/build/compiler_builtins-edc8c8fe10618157/out" "-L" "/home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib" "-l" "advapi32" "-l" "ws2_32" "-l" "userenv" "-l" "shell32" "-Wl,-Bstatic" "-Wl,--whole-archive" "/tmp/rustc.B2b0Zr1fYMAO/librand-697a54e1da5acdea.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.B2b0Zr1fYMAO/liballoc_system-4d0b71301766050c.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.B2b0Zr1fYMAO/libpanic_unwind-dc95fd7ae7860bd0.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.B2b0Zr1fYMAO/libunwind-541690d23dc9414e.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.B2b0Zr1fYMAO/liblibc-db1f4145a33c77a5.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.B2b0Zr1fYMAO/liballoc-237099905b1145a0.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.B2b0Zr1fYMAO/libstd_unicode-a5799758e2da97b6.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.B2b0Zr1fYMAO/libcore-7e6ce05447c01df0.rlib" "-Wl,--no-whole-archive" "/tmp/rustc.B2b0Zr1fYMAO/libcompiler_builtins-9412c7b4e437c7bd.rlib" "-l" "gcc_eh" "-l" "pthread" "-shared" "-Wl,-Bdynamic" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "/home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib/rsend.o"
  = note: i686-w64-mingw32-gcc: error: /home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib/dllcrt2.o: No such file or directory
          i686-w64-mingw32-gcc: error: /home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o: No such file or directory
          i686-w64-mingw32-gcc: error: /home/user/.xargo/lib/rustlib/i686-pc-windows-gnu/lib/rsend.o: No such file or directory

It seems to me that xargo builds std inside temporary directory, e.g. /tmp/xargo.QY0kDly5zQlB/target/i686-pc-windows-gnu/release/deps/… and then, during linking process, linker (gcc?) doesn’t lookup missing files in proper directory.

I have missing file (dllcrt2.o) in a directory:

/usr/i686-w64-mingw32/lib
...
-rw-r--r-- 1 root root   13458 Jan 10  2014 dllcrt2.o
...

How can I pass this directory as a library find path to linker (gcc) through xargo?

I’ve attempted:

  1. xargo build --target=i686-pc-windows-gnu --verbose – -C link-args=-L/usr/i686-w64-mingw32/lib
  2. LIBRARY_PATH=/usr/i686-w64-mingw32/lib xargo build --target=i686-pc-windows-gnu --verbose
  3. adding to Cargo.toml
    [profile.all]
    rustflags = ["-Clink-args=-L/usr/i686-w64-mingw32/lib"]
    or
    rustflags = ["-C", “-L/usr/i686-w64-mingw32/lib”]

I’m highly appreciate if someone points me to the tutorial or manual. I haven’t found needed information at doc.crates.io at page manifest.

And I don’t know either where to find the other two files (rsbegin.o, rsend.o), nor what they are responsible to.

I appreciate any help with my issuses.

P.S.

rustc -vV
rustc 1.22.0-nightly (4c053db23 2017-10-22)
binary: rustc
commit-hash: 4c053db233d69519b548e5b8ed7192d0783e582a
commit-date: 2017-10-22
host: x86_64-unknown-linux-gnu
release: 1.22.0-nightly
LLVM version: 4.0
cargo version

cargo 0.23.0-nightly (e447ac7e9 2017-09-27)


#2

Okay, rsbegin.o and rsend.o are the so called “compiler runtime startup objects”. They contain code needed to correctly initialize the compiler runtime rtstartup.


#3

Have you tried cross?