- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我运行x86_64 Fedora Linux 31主机,并希望编译一些最简单的rust代码:
fn main() {
println!("Hello, world!");
}
[pfemidi@pfemidi hello_cargo]$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home: /home/pfemidi/.rustup
installed targets for active toolchain
--------------------------------------
i686-pc-windows-gnu
i686-unknown-linux-gnu
i686-unknown-linux-musl
x86_64-pc-windows-gnu
x86_64-unknown-linux-gnu
x86_64-unknown-linux-musl
active toolchain
----------------
stable-x86_64-unknown-linux-gnu (default)
rustc 1.39.0 (4560ea788 2019-11-04)
[pfemidi@pfemidi hello_cargo]$
#include <iomanip>
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}
[target.i686-pc-windows-gnu]
linker = "i686-w64-mingw32-gcc"
ar = "i686-w64-mingw32-ar"
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
ar = "x86_64-w64-mingw32-ar"
cargo build --release --target i686-pc-windows-gnu --verbose
cargo build --release --target x86_64-pc-windows-gnu --verbose
[pfemidi@pfemidi hello_cargo]$ cargo build --release --target i686-pc-windows-gnu --verbose
Compiling hello_cargo v0.1.0 (/home/pfemidi/mywork/rust/hello_cargo)
Running `rustc --edition=2018 --crate-name hello_cargo src/main.rs --color always --crate-type bin --emit=dep-info,link -C opt-level=3 -C panic=abort -C metadata=3801b83c24480675 -C extra-filename=-3801b83c24480675 --out-dir /home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps --target i686-pc-windows-gnu -C ar=i686-w64-mingw32-ar -C linker=i686-w64-mingw32-gcc -L dependency=/home/r/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps -L dependency=/home/r/mywork/rust/hello_cargo/target/release/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/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/crt2.o" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/rsbegin.o" "-L" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.0.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.1.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.10.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.11.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.12.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.2.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.3.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.4.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.5.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.6.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.7.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.8.rcgu.o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.hello_cargo.ejabbyqy-cgu.9.rcgu.o" "-o" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.exe" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps/hello_cargo-3801b83c24480675.3miif37looiovbes.rcgu.o" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps" "-L" "/home/pfemidi/mywork/rust/hello_cargo/target/release/deps" "-L" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libstd-78187cf09a9bef6f.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libpanic_abort-699459bd9d6c1638.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libhashbrown-397a481a32803af5.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/librustc_std_workspace_alloc-27eb482dce24475f.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libbacktrace-046a61f77fc212c5.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libbacktrace_sys-8c6fe5218eaa7203.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/librustc_demangle-4d4d47417516248c.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libunwind-ef8ccbbd42d1b53f.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libcfg_if-bbe68dc13352b6cc.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/liblibc-b6447d8e4c58855b.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/liballoc-3890c13f15229667.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/librustc_std_workspace_core-ceab434c37c7417c.rlib" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libcore-3b2fced4ccf446c5.rlib" "-Wl,--end-group" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libcompiler_builtins-7e358676639674ac.rlib" "-Wl,-Bdynamic" "-ladvapi32" "-lws2_32" "-luserenv" "-Wl,-Bstatic" "-lgcc_eh" "-lpthread" "-Wl,-Bdynamic" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmsvcrt" "-luser32" "-lkernel32" "/home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/rsend.o"
= note: /usr/lib/gcc/i686-w64-mingw32/9.2.1/../../../../i686-w64-mingw32/bin/ld: cannot find -lpthread
collect2: error: ld returned 1 exit status
error: aborting due to previous error
error: could not compile `hello_cargo`.
Caused by:
process didn't exit successfully: `rustc --edition=2018 --crate-name hello_cargo src/main.rs --color always --crate-type bin --emit=dep-info,link -C opt-level=3 -C panic=abort -C metadata=3801b83c24480675 -C extra-filename=-3801b83c24480675 --out-dir /home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps --target i686-pc-windows-gnu -C ar=i686-w64-mingw32-ar -C linker=i686-w64-mingw32-gcc -L dependency=/home/pfemidi/mywork/rust/hello_cargo/target/i686-pc-windows-gnu/release/deps -L dependency=/home/pfemidi/mywork/rust/hello_cargo/target/release/deps` (exit code: 1)
[pfemidi@pfemidi hello_cargo]$
最佳答案
经过一番思考,我能够解决该问题,而无需使用cross和类似的工具,而只需在 cargo 中指定特定的目标即可将Rust中的项目从Linux主机交叉编译到Windows目标。当然,测试和运行项目将失败(如果没有安装任何类似wine的仿真器),但是仅创建Windows目标就可以顺利进行。 BTW Rust最初是作为交叉编译器开发的,因此拥有完整的工作项目并通过Linux中的所有测试,几乎可以肯定,在Windows中对该项目进行简单的交叉编译不会以任何方式破坏它。
自从我运行Fedora Linux 31以来,以下所有内容都适用于此发行版。但是我认为其他Linux发行版之间没有显着差异。而且我只考虑pc-windows-gnu Rust目标,而pc-windows-msvc目标并不重要。
首先,确保安装了所有必需的用于交叉编译的MinGW软件包:
[pfemidi@pfemidi ~]$ rpm -qa | grep mingw | sort
mingw32-binutils-2.32-6.fc31.x86_64
mingw32-cpp-9.2.1-1.fc31.x86_64
mingw32-crt-6.0.0-2.fc31.noarch
mingw32-filesystem-110-1.fc31.noarch
mingw32-gcc-9.2.1-1.fc31.x86_64
mingw32-headers-6.0.0-2.fc31.noarch
mingw32-winpthreads-6.0.0-2.fc31.noarch
mingw32-winpthreads-static-6.0.0-2.fc31.noarch
mingw64-binutils-2.32-6.fc31.x86_64
mingw64-cpp-9.2.1-1.fc31.x86_64
mingw64-crt-6.0.0-2.fc31.noarch
mingw64-filesystem-110-1.fc31.noarch
mingw64-gcc-9.2.1-1.fc31.x86_64
mingw64-headers-6.0.0-2.fc31.noarch
mingw64-winpthreads-6.0.0-2.fc31.noarch
mingw64-winpthreads-static-6.0.0-2.fc31.noarch
mingw-binutils-generic-2.32-6.fc31.x86_64
mingw-filesystem-base-110-1.fc31.noarch
[pfemidi@pfemidi ~]$
[pfemidi@pfemidi rust]$ cargo new foobar
Created binary (application) `foobar` package
[pfemidi@pfemidi rust]$ cat foobar/src/main.rs
fn main() {
println!("Hello, world!");
}
[pfemidi@pfemidi rust]$
[pfemidi@pfemidi rust]$ cd foobar
[pfemidi@pfemidi foobar]$ mkdir .cargo
[pfemidi@pfemidi foobar]$ cat > .cargo/config
[target.i686-pc-windows-gnu]
linker = "i686-w64-mingw32-gcc"
ar = "i686-w64-mingw32-ar"
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
ar = "x86_64-w64-mingw32-ar"
[pfemidi@pfemidi foobar]$
[pfemidi@pfemidi foobar]$ cargo build --target i686-pc-windows-gnu
Compiling foobar v0.1.0 (/home/pfemidi/mywork/rust/foobar)
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"
...
= note: /usr/lib/gcc/i686-w64-mingw32/9.2.1/../../../../i686-w64-mingw32/bin/ld: /home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/crt2.o:crtexe.c:(.text+0x75): undefined reference to `__onexitend'
/usr/lib/gcc/i686-w64-mingw32/9.2.1/../../../../i686-w64-mingw32/bin/ld: /home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/crt2.o:crtexe.c:(.text+0x7a): undefined reference to `__onexitbegin'
collect2: error: ld returned 1 exit status
error: aborting due to previous error
error: could not compile `foobar`.
To learn more, run the command again with --verbose.
[pfemidi@pfemidi foobar]$
__onexitend
的 undefined reference ”和“对
__onexitbegin
的 undefined reference ”。事实是pc-windows-gnu目标的Rust组件是用MinGW 6.3.0构建的,但Fedora Linux 31中存在MinGW版本9.2.1。因此,由于编译器版本不匹配,CRT有所不同。好的,让我们将crt2.o从Fedora Linux MinGW存储库复制到i686-pc-windows-gnu组件的Rust目录中。与crt2.o一起,我们还复制了dllcrt2.o,它是动态库的入口点,因为crt2.o是独立的可执行文件。以防万一,我们保存原始文件:
[pfemidi@pfemidi foobar]$ cd ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/
[pfemidi@pfemidi lib]$ mv crt2.o crt2.o.ori
[pfemidi@pfemidi lib]$ mv dllcrt2.o dllcrt2.o.ori
[pfemidi@pfemidi lib]$ cp /usr/i686-w64-mingw32/sys-root/mingw/lib/crt2.o .
[pfemidi@pfemidi lib]$ cp /usr/i686-w64-mingw32/sys-root/mingw/lib/dllcrt2.o .
[pfemidi@pfemidi lib]$ cd -
/home/pfemidi/mywork/rust/foobar
[pfemidi@pfemidi foobar]$
[pfemidi@pfemidi foobar]$ cargo build --target i686-pc-windows-gnu
Compiling foobar v0.1.0 (/home/pfemidi/mywork/rust/foobar)
Finished dev [unoptimized + debuginfo] target(s) in 0.19s
[pfemidi@pfemidi foobar]$
[pfemidi@pfemidi foobar]$ cargo build --target x86_64-pc-windows-gnu
Compiling foobar v0.1.0 (/home/pfemidi/mywork/rust/foobar)
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"
...
= note: /usr/lib/gcc/x86_64-w64-mingw32/9.2.1/../../../../x86_64-w64-mingw32/bin/ld: /home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/crt2.o:crtexe.c:(.rdata$.refptr.__onexitbegin[.refptr.__onexitbegin]+0x0): undefined reference to `__onexitbegin'
/usr/lib/gcc/x86_64-w64-mingw32/9.2.1/../../../../x86_64-w64-mingw32/bin/ld: /home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/crt2.o:crtexe.c:(.rdata$.refptr.__onexitend[.refptr.__onexitend]+0x0): undefined reference to `__onexitend'
collect2: error: ld returned 1 exit status
error: aborting due to previous error
error: could not compile `foobar`.
To learn more, run the command again with --verbose.
[pfemidi@pfemidi foobar]$
[pfemidi@pfemidi foobar]$ cd ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/
[pfemidi@pfemidi lib]$ mv crt2.o crt2.o.ori
[pfemidi@pfemidi lib]$ mv dllcrt2.o dllcrt2.o.ori
[pfemidi@pfemidi lib]$ cp /usr/x86_64-w64-mingw32/sys-root/mingw/lib/crt2.o .
[pfemidi@pfemidi lib]$ cp /usr/x86_64-w64-mingw32/sys-root/mingw/lib/dllcrt2.o .
[pfemidi@pfemidi lib]$ cd -
/home/pfemidi/mywork/rust/foobar
[pfemidi@pfemidi foobar]$
[pfemidi@pfemidi foobar]$ cargo build --target x86_64-pc-windows-gnu
Compiling foobar v0.1.0 (/home/pfemidi/mywork/rust/foobar)
Finished dev [unoptimized + debuginfo] target(s) in 0.20s
[pfemidi@pfemidi foobar]$
[pfemidi@pfemidi foobar]$ cat src/main.rs
fn main() {
println!("Hello, world!");
panic!("I'm panicked!"); // <-- here it is
}
[pfemidi@pfemidi foobar]$
[pfemidi@pfemidi foobar]$ cargo build --target x86_64-pc-windows-gnu
Compiling foobar v0.1.0 (/home/pfemidi/mywork/rust/foobar)
Finished dev [unoptimized + debuginfo] target(s) in 0.16s
[pfemidi@pfemidi foobar]$
[pfemidi@pfemidi foobar]$ cargo build --target i686-pc-windows-gnu
Compiling foobar v0.1.0 (/home/pfemidi/mywork/rust/foobar)
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"
...
= note: /usr/lib/gcc/i686-w64-mingw32/9.2.1/../../../../i686-w64-mingw32/bin/ld: /home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libpanic_unwind-0c029c00da54fbf5.rlib(panic_unwind-0c029c00da54fbf5.panic_unwind.2hgzd7yq-cgu.0.rcgu.o): in function `ZN12panic_unwind3imp5panic17h03027a0e504502cdE':
/rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libpanic_unwind/gcc.rs:73: undefined reference to `_Unwind_RaiseException'
/usr/lib/gcc/i686-w64-mingw32/9.2.1/../../../../i686-w64-mingw32/bin/ld: /home/pfemidi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/libpanic_unwind-0c029c00da54fbf5.rlib(panic_unwind-0c029c00da54fbf5.panic_unwind.2hgzd7yq-cgu.0.rcgu.o): in function `rust_eh_unwind_resume':
/rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14\/src\libpanic_unwind/gcc.rs:327: undefined reference to `_Unwind_Resume'
collect2: error: ld returned 1 exit status
error: aborting due to previous error
error: could not compile `foobar`.
To learn more, run the command again with --verbose.
[pfemidi@pfemidi foobar]$
_Unwind_RaiseException
的 undefined reference ”和“对
_Unwind_Resume
的 undefined reference ”。但是,这个问题也得到了解决,尽管不像上一个简单地替换CRT crt2.o和dllcrt2.o文件那样简单。
[pfemidi@pfemidi foobar]$ cd ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/i686-pc-windows-gnu/lib/
[pfemidi@pfemidi lib]$ cp ~/rpmbuild/BUILD/gcc-9.2.1-20190827/build_win32/i686-w64-mingw32/libgcc/libgcc_eh.a .
[pfemidi@pfemidi lib]$ cd -
/home/pfemidi/mywork/rust/foobar
[pfemidi@pfemidi foobar]$ cargo build --target i686-pc-windows-gnu
Compiling foobar v0.1.0 (/home/pfemidi/mywork/rust/foobar)
Finished dev [unoptimized + debuginfo] target(s) in 0.30s
[pfemidi@pfemidi foobar]$
关于linux - 从Fedora Linux主机到Windows目标的交叉编译Rust找不到依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59385341/
例如,我有一个父类Author: class Author { String name static hasMany = [ fiction: Book,
代码如下: dojo.query(subNav.navClass).forEach(function(node, index, arr){ if(dojo.style(node, 'd
我有一个带有 Id 和姓名的学生表和一个带有 Id 和 friend Id 的 Friends 表。我想加入这两个表并找到学生的 friend 。 例如,Ashley 的 friend 是 Saman
我通过互联网浏览,但仍未找到问题的答案。应该很容易: class Parent { String name Child child } 当我有一个 child 对象时,如何获得它的 paren
我正在尝试创建一个以 Firebase 作为我的后端的社交应用。现在我正面临如何(在哪里?)找到 friend 功能的问题。 我有每个用户的邮件地址。 我可以访问用户的电话也预订。 在传统的后端中,我
我主要想澄清以下几点: 1。有人告诉我,在 iOS 5 及以下版本中,如果您使用 Game Center 设置多人游戏,则“查找 Facebook 好友”(如与好友争夺战)的功能不是内置的,因此您需要
关于redis docker镜像ENTRYPOINT脚本 docker-entrypoint.sh : #!/bin/sh set -e # first arg is `-f` or `--some-
我是一名优秀的程序员,十分优秀!