2

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 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Had similar issues under macos. I just had to adjust paths a bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.