问题
I Want To Cross Compile Some Rust Code from Ubuntu to Windows, and receive an error about onexitbegin.
Tried to follow various suggestions, but they don't have my specific error message: crt2.o:crtexe.c: (.rdata$.refptr.__onexitend[.refptr.__onexitend]+0x0): undefined reference to `__onexitend' collect2: error: ld returned 1 exit status
cargo build --release --target x86_64-pc-windows-gnu
Expected to get something built, but it blows up.
The output says this:
/usr/bin/x86_64-w64-mingw32-ld: /home/vince/.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/bin/x86_64-w64-mingw32-ld: /home/vince/.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'
回答1:
If you receive messages about an undefined reference to
__onexitbegin` or something similar, you may have an older version of crt2.o, instead of the version that ming has available to it. I did! (running on stable rust 1.35).
Try this in your terminal and see if it helps:
cd ~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/
mv crt2.o crt2.o.bak
cp /usr/x86_64-w64-mingw32/lib/crt2.o ./
Your executable should now be built for windows.
来源:https://stackoverflow.com/questions/56602101/i-cant-get-cross-compiling-from-ubuntu-to-windows-working