libusb-sys icon indicating copy to clipboard operation
libusb-sys copied to clipboard

Fail to build when cross-compiling for Windows

Open beamspease opened this issue 8 years ago • 1 comments

Probably the same cause as #6

Build command:

cargo build --target i686-pc-windows-gnu

Error:

error: failed to run custom build command for `libusb-sys v0.2.3`
process didn't exit successfully: `target/debug/build/libusb-sys-6bbfe3932132cdbf/build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "Cross compilation detected. Use PKG_CONFIG_ALLOW_CROSS=1 to override"', /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/result.rs:868
note: Run with `RUST_BACKTRACE=1` for a backtrace.

beamspease avatar Apr 25 '17 11:04 beamspease

Hello, first you may edit the file vim ~/.cargo/config

then add following such as [target.x86_64-pc-windows-gnu] linker="/Path/Cross/Compiler/x86_64-pc-windows-gnu/bin/x86_64-w64-mingw32-gcc" ar="/Path/Cross/Compiler/x86_64-pc-windows-gnu/bin/x86_64-w64-mingw32-gcc-ar"

then download the libusb source from libusb website

in the source folder you may run

./configure CC=/Path/Cross/Compiler/x86_64-pc-windows-gnu/bin/x86_64-w64-mingw32-gcc --prefix=/PrefixPath/lib-cross/x86_64-pc-windows-gnu --host=x86_64-w64-mingw32 --disable-udev

and run

make install

if you want to make the host for windows you will edit the --host=x86_64-w64-mingw32 or --host=i686-w64-mingw32

then in the folder /PrefixPath/lib-cross/x86_64-pc-windows-gnu will appear the files.

Set the environment

PKG_CONFIG_LIBDIR=/PrefixPath/lib-cross/x86_64-pc-windows-gnu/lib/pkgconfig PKG_CONFIG_ALLOW_CROSS=1

[email protected]

Good luck!

NightBalance avatar Sep 04 '18 17:09 NightBalance