-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot cross-compile .a file from linux to windows #523
Comments
Thanks for the report, but you'll need to configure the toolchain if it's non-standard, such as in this case. Otherwise you'll need to arrange to have an appropriate toolchain installed. |
Could you give an example of what you mean? The crate docs say
So I was under the impression things like this would be detected automatically. I don't see anything on |
This crate performs a best effort, but it can't figure out everything under the sun. More common than not the toolchain doesn't even exist on the system, but unfortunately this crate can't really figure that out. |
If anyone wants to work on this then PRs would be very welcome! |
The problem description is misleading. Would (*) It might be possible to install and run MSVC compiler under wine, but then it would be more appropriate to run matching Rust installation there too. |
I don't mind if this doesn't work honestly, I just wish the error message were more helpful, rather than looking like a bug in the cc crate. |
It's definitely possible to cross compile Rust to msvc targets using As far as cc-rs is concerned, cross compiling could be made to work in theory, assuming that |
I think an immediate fix here would be, as jyn suggests, to provide a more helpful error when using a GNU tool for msvc targets because this is incompatible. This would still allow manual overrides (e.g. by setting Attempting to automatically find and compile with clang-cl (or even clang proper, but that might be more work) could also be useful but is much more involved and may still requires some manual set up by the user. A more limited approach would be to correctly use llvm tools if In any case, better diagnostics are good even if we try something more involved later. |
Well, while Linux clang-cl is indeed capable of generating PE-COFF .obj files, you lack headers, libraries and link.exe(*). In other words, you still can't do the actual useful stuff, like compiling arbitrary C(**) or link an executable binary. Be it just Rust or a mixture of [again, "pure"!] C and Rust. (*) No, clang-cl does not do the linking, but relies on MSVC link.exe being available. Just like rustc. |
|
llvm-link is a bitcode linker. It won't emit PE-COFF (or any other) executable. |
Sorry, I mistyped that. lld-link is what I meant. |
Oh! And so you mean that you'd be able to actually replace MSVC linker with it? Why doesn't clang-cl call it? BTW, Rust comes with lld-link. As far as I understand it's used with no-std targets, like embedded ones. Would Rust's lld-link up to the job? |
Rust's
or
|
Wow! Well, it's still only one out of three missing components on Linux, headers, libraries, Hmm, #758 could have picked it up with |
Hm, adjusting that code to search for |
The |
My Ubuntu 22.04 install does have /usr/bin$ ls llvm-lib*
llvm-lib llvm-lib-14 llvm-libtool-darwin-14 Granted though, a more thorough search would be nice. |
Well, I for one don't have llvm-lib on the PATH. So one probably shouldn't count on it. But either way, the question about #758 not picking up llvm-lib was rather "academic." As it won't make the cross-compilation scenario in question maintainable. If one wants to cross-compile for Windows, mingw is the answer. |
Sounds like something done with |
Given the following
Cargo.toml
:build.rs
:and
example.c
:the
cc
crate will incorrectly try to use the Windows toolchain instead of the host toolchain.Full output from
cargo build
Note that it correctly detects the host and target platforms, but still tries to use
lib.exe
instead ofld
.The text was updated successfully, but these errors were encountered: