【问题标题】:mingw cross compiling error - undefined reference to `__mingw_get_msvcrt_handle'mingw 交叉编译错误 - 未定义对“__mingw_get_msvcrt_handle”的引用
【发布时间】:2015-12-31 03:36:39
【问题描述】:

我可以成功地从 Linux for Windows 交叉编译一个简单的 hello world 程序的 exe。现在,我正在尝试交叉编译一个更复杂的程序。这是一个 Rust 程序,但它不是问题的原因,因为已经生成了一个 .o。

知道为什么我会收到 undefined reference to `__mingw_get_msvcrt_handle' 错误吗?我正在使用 rubenvb-4.7.0.

预构建的工具链

命令行是:

/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

这些是错误消息:

/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

【问题讨论】:

标签: gcc linker mingw rust cross-compiling


【解决方案1】:

我找到了问题。

我指的是this post 进行交叉编译。要获得 x86_64 的 rustlib,我下载包 http://static.rust-lang.org/dist/rustc-1.5.0-x86_64-pc-windows-gnu.tar.gz 并将该库复制到我在 Linux 中安装的 rustc 下的 rustlib/x86_64-pc-windows-gnu

但是,__mingw_get_msvcrt_handle 没有在来自 rustlang 的 rustlib 中定义。我用的是mingw gcc的交叉编译器,看来你必须使用mingw gcc提供的lib。

我的解决方案是将 mingw gcc lib 文件夹中的所有文件(*.a、*.o 等)复制到 rustlib/x86_64-pc-windows-gnu。然后就可以了。

【讨论】:

    【解决方案2】:

    在 Windows 上编译时,强烈建议使用 multirust 而不是 rust。在我看来,您正试图以某种方式将 msvc 编译的 rust 与 mingw 混合。如果没有更多信息,还不清楚事情是如何/哪里出了问题。

    【讨论】:

    • OP 未在 Windows 上编译:“从 Linux 为 Windows 交叉编译 exe”。如果您认为 OP 应该提供更具体的信息,我建议您在问题中添加评论。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-04
    • 2011-02-06
    • 2015-07-12
    • 1970-01-01
    • 2016-06-23
    • 1970-01-01
    相关资源
    最近更新 更多