0

I can successfully cross compile an exe from Linux for Windows of a simple hello world program. Now, I am trying to cross compile a more complicated program. It's a Rust program, but it is not the cause of the issue, as an .o has been produced.

Any idea why I get an undefined reference to `__mingw_get_msvcrt_handle' error? I am using a toolchain prebuilt by rubenvb-4.7.0.

The command line is:

/inst_temp/mingw32_3/mingw64/bin/x86_64-w64-mingw32-gcc -Wl,--enable-long-section-names -fno-use-linker-plugin -Wl,--nxcompat -static-libgcc -m64 -L /mytool/var/lib/rustlib/x86_64-pc-windows-gnu/lib /rust.code/study/prj3/target/x86_64-pc-windows-gnu/debug/study_cross_rust.0.o -o /rust.code/study/prj3/target/x86_64-pc-windows-gnu/debug/study_cross_rust.exe -Wl,--gc-sections -L /rust.code/study/prj3/target/x86_64-pc-windows-gnu/debug -L /rust.code/study/prj3/target/x86_64-pc-windows-gnu/debug/deps -L /mytool/var/lib/rustlib/x86_64-pc-windows-gnu/lib -L /rust.code/study/prj3/.rust/lib/x86_64-pc-windows-gnu -L /rust.code/study/prj3/lib/x86_64-pc-windows-gnu -Wl,-Bstatic -Wl,-Bdynamic /mytool/var/lib/rustlib/x86_64-pc-windows-gnu/lib/libstd-35c36e89.rlib /mytool/var/lib/rustlib/x86_64-pc-windows-gnu/lib/libcollections-35c36e89.rlib /mytool/var/lib/rustlib/x86_64-pc-windows-gnu/lib/librustc_unicode-35c36e89.rlib /mytool/var/lib/rustlib/x86_64-pc-windows-gnu/lib/librand-35c36e89.rlib /mytool/var/lib/rustlib/x86_64-pc-windows-gnu/lib/liballoc-35c36e89.rlib /mytool/var/lib/rustlib/x86_64-pc-windows-gnu/lib/liballoc_jemalloc-35c36e89.rlib /mytool/var/lib/rustlib/x86_64-pc-windows-gnu/lib/liblibc-35c36e89.rlib /mytool/var/lib/rustlib/x86_64-pc-windows-gnu/lib/libcore-35c36e89.rlib -l ws2_32 -l userenv -l advapi32 -l compiler-rt

These are the error messages:

/inst_temp/mingw32_3/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o: In function `__mingw_prepare_except_for_msvcr80_and_higher':
/home/ruben/mingw-w64/toolchain/src/mingw-w64/tags/v2.0.3/mingw-w64-crt/crt/crtexe.c:430: undefined reference to `__mingw_get_msvcrt_handle'
collect2: error: ld returned 1 exit status
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
palazzo train
  • 3,229
  • 1
  • 19
  • 40

2 Answers2

1

I have found the issue.

I was referring to this post for the cross compilation. To have the rustlib for x86_64, I download the package http://static.rust-lang.org/dist/rustc-1.5.0-x86_64-pc-windows-gnu.tar.gz and copy the lib to the rustlib/x86_64-pc-windows-gnu under my rustc installation in Linux.

However, the __mingw_get_msvcrt_handle is not defined in this rustlib from rustlang. I am using the cross compiler of mingw gcc and it seems that you must use the lib provided by mingw gcc.

My solution is to copy all files (*.a, *.o, etc) in mingw gcc lib folder to the rustlib/x86_64-pc-windows-gnu. It works then.

Mike P
  • 742
  • 11
  • 26
palazzo train
  • 3,229
  • 1
  • 19
  • 40
-1

When compiling on windows it's highly suggested to use multirust instead of just rust. It looks to me like you are trying to mix msvc compiled rust with mingw in some fashion. Without more info it's not really clear how/where things are going wrong.

Script and Compile
  • 1,286
  • 3
  • 10
  • 17
  • OP is not compiling on Windows: "*cross compile an exe from Linux for Windows*". If there's more specific information you think OP should provide, I'd encourage you to add a comment to the question. – Shepmaster Jan 01 '16 at 23:49