PyO3 / pyo3

Rust bindings for the Python interpreter
https://pyo3.rs
Apache License 2.0
11.96k stars 734 forks source link

Can't cross-compile rust lib from linux to windows #666

Closed UltraMachine closed 4 years ago

UltraMachine commented 4 years ago

πŸ› Bug Reports

When reporting a bug, please provide the following information. If this is not a bug report you can just discard this template.

🌍 Environment

πŸ’₯ Reproducing

I'm trying to compile this lib on linux for windows.

Running with cargo build --release --target "x86_64-pc-windows-gnu" -v, I'm getting this error:

error: linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1
  |
  = note: "x86_64-w64-mingw32-gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-m64" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/dllcrt2.o" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/rsbegin.o" "-L" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.sc2pathlib.a45jfogg-cgu.0.rcgu.o" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.sc2pathlib.a45jfogg-cgu.1.rcgu.o" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.sc2pathlib.a45jfogg-cgu.10.rcgu.o" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.sc2pathlib.a45jfogg-cgu.11.rcgu.o" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.sc2pathlib.a45jfogg-cgu.12.rcgu.o" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.sc2pathlib.a45jfogg-cgu.13.rcgu.o" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.sc2pathlib.a45jfogg-cgu.14.rcgu.o" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.sc2pathlib.a45jfogg-cgu.15.rcgu.o" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.sc2pathlib.a45jfogg-cgu.2.rcgu.o" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.sc2pathlib.a45jfogg-cgu.3.rcgu.o" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.sc2pathlib.a45jfogg-cgu.4.rcgu.o" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.sc2pathlib.a45jfogg-cgu.5.rcgu.o" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.sc2pathlib.a45jfogg-cgu.6.rcgu.o" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.sc2pathlib.a45jfogg-cgu.7.rcgu.o" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.sc2pathlib.a45jfogg-cgu.8.rcgu.o" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.sc2pathlib.a45jfogg-cgu.9.rcgu.o" "-o" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.dll" "-Wl,--version-script=/tmp/rustcINaZNj/list" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.4qrj5y82yo4grzjd.rcgu.o" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps" "-L" "/home/armageddon/projects/sc2-pathlib/target/release/deps" "-L" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib" "-Wl,-Bstatic" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/libpathfinding-de2d6bd9c2051d11.rlib" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/libfixedbitset-57795ffa7b25cc7f.rlib" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/libitertools-49e282049a7e60d6.rlib" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/libeither-69f3815dfbd07322.rlib" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/libindexmap-c7188f68cefb1405.rlib" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/libpyo3-5011b13c2f54e62b.rlib" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/libnum_traits-20dc20a50dc118ef.rlib" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/libspin-9b6bb5af72046670.rlib" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/libunindent-07f758d7f0b54cfb.rlib" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/liblibc-ba8355680f151b78.rlib" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/libinventory-2adc9d42c32988f9.rlib" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/libindoc-91148f62fc14448a.rlib" "/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/libpaste-31f65bf4a5d1b11e.rlib" "-Wl,--start-group" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libstd-747648f71118c692.rlib" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libpanic_unwind-3cf77e8c834e1515.rlib" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libhashbrown-37849e1cdf2d5ce0.rlib" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/librustc_std_workspace_alloc-ea5d6bc0ec7058c9.rlib" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libbacktrace-b5ec048bcf1e3694.rlib" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libbacktrace_sys-f21dfcd83a2909fb.rlib" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/librustc_demangle-c2033e316e103224.rlib" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libunwind-fe6eb7460b9ef950.rlib" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libcfg_if-12ebe9a4ac4ed76a.rlib" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/liblibc-6967320188af24fd.rlib" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/liballoc-318fbdaec35b4968.rlib" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/librustc_std_workspace_core-07539409623004fc.rlib" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libcore-3a26d76fb9e35800.rlib" "-Wl,--end-group" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libcompiler_builtins-c948b6664b7af323.rlib" "-Wl,-Bdynamic" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-lpythonXY" "-ladvapi32" "-lws2_32" "-luserenv" "-Wl,-Bstatic" "-lgcc_eh" "-lpthread" "-shared" "-Wl,--out-implib,/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/sc2pathlib.dll.lib" "-Wl,-Bdynamic" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmsvcrt" "-luser32" "-lkernel32" "/home/armageddon/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/rsend.o"
  = note: /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY
          collect2: error: ld returned 1 exit status

error: aborting due to previous error

error: could not compile `sc2pathlib`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name sc2pathlib src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type cdylib --emit=dep-info,link -C opt-level=3 -C metadata=c436664892c0a209 --out-dir /home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps --target x86_64-pc-windows-gnu -C ar=x86_64-w64-mingw32-gcc-ar -C linker=x86_64-w64-mingw32-gcc -L dependency=/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps -L dependency=/home/armageddon/projects/sc2-pathlib/target/release/deps --extern pathfinding=/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/libpathfinding-de2d6bd9c2051d11.rlib --extern pyo3=/home/armageddon/projects/sc2-pathlib/target/x86_64-pc-windows-gnu/release/deps/libpyo3-5011b13c2f54e62b.rlib` (exit code: 1)
kngwyu commented 4 years ago

Sorry, I'm not sure it's possible now...

benoitbayol commented 4 years ago

Hey is there any update on this one ?

I am trying to build a python library for windows with maturin using the same kind of setting by using cross : https://github.com/rust-embedded/cross

It is frustrating since the only problem is at link and normally everything is there.

I tried to pass some --rustc-extra-args="-l dylib=pythonXY:python38" to maturin in order to force the finding. But then maturin tell me I have no #[link(...)] in my crate, which is normal since it is pyo3 related and not user-defined crate related.

I have no insight how to make a workaround on that :/ and I want to avoid using travis and a windows vm. I prefer to stay in a full linux setting with cross-compilation for mac and win.

Do you have any advice for me to tweak something in my build setting or directly adding a feature in the code ?

davidhewitt commented 4 years ago

@benoitbayol from what I read you're building a Python extension module, and have the extension_module feature enabled?

In theory you shouldn't need linking at all for an extension module, so what pyo3 is doing here is definitely wrong. We have some open discussion around the extension_module feature which I'd like to resolve soon - see #771 and #904

Maybe I will provide a patch later in the next week or so...

benoitbayol commented 4 years ago

Yes I have extension_module.

A patch would be so great :)

davidhewitt commented 4 years ago

@benoitbayol can you please have a go with https://github.com/PyO3/pyo3/pull/923 and let me know if this resolves your problem? Thanks.

mahmoudfarouq commented 4 years ago

Hey is there any updates on this? I'm having the same issue and it's really frustrating

davidhewitt commented 4 years ago

@MahmoudFarouq can you try the branch in the PR I linked and let me know if that works for you?

mahmoudfarouq commented 4 years ago

@davidhewitt Just tried it now, didn't work. however, before the output contained

/usr/bin/x86_64-w64-mingw32-ld: cannot find -lpythonXY

but now it's

/usr/bin/x86_64-w64-mingw32-ld: cannot find -lpython3.6m

XY became the python version. Also notice i had to use a nightly build of rust.

This is my Cargo.toml in case i'm doing something wrong

[dependencies]
pyo3 = { git = "https://github.com/davidhewitt/pyo3", branch = "fix-cross-compile" }
davidhewitt commented 4 years ago

@MahmoudFarouq great, thanks for feedback. Can you please look in your PYO3_CROSS_LIB_DIR and tell me the name of the python shared library in that directory? (I think it will be a .dll file)

davidhewitt commented 4 years ago

Also notice i had to use a nightly build of rust.

Ah yes that branch is quite old, I should probably rebase it πŸ˜…

mahmoudfarouq commented 4 years ago

@MahmoudFarouq great, thanks for feedback. Can you please look in your PYO3_CROSS_LIB_DIR and tell me the name of the python shared library in that directory? (I think it will be a .dll file)

I don't have it set, can you please tell me to what should i set it?

davidhewitt commented 4 years ago

I think it should should be the "libs" subdirectory of the w64-mingw32 Python install you're trying to link to with your cross-compile.

(There's a bit more detail on cross-compiling here: https://pyo3.rs/v0.11.1/building_and_distribution.html#cross-compiling)

mahmoudfarouq commented 4 years ago

A Python interpreter that's already been compiled for your target.

@davidhewitt I think this is what i'm missing, donno how to fix though.

davidhewitt commented 4 years ago

TBH looking at https://wiki.python.org/moin/WindowsCompilers#GCC_-_MinGW-w64_.28x86.2C_x64.29 support for mingw might have stopped at Python 3.4?

Afraid I haven't tried to do this cross-compile myself, so also don't have any idea how you would get a suitable build of Python to link against with the mingw target.

What are you trying to do this cross-compile for? If it's to package a wheel to distribute for other users, then I think you want to be targeting windows-msvc instead of windows-gnu, because afaik most Python installs on windows are built against the msvc target.

FWIW, the python packaging docs suggest using Appveyor to build the package on a Windows host, rather than cross-compile (Github Actions also supports Windows hosts).

mahmoudfarouq commented 4 years ago

I didn't want to use windows and msvc because this would be a big install and setup for a really tiny package, but seems this is my only choice, Thanks man for your help :"D