gpt4 book ai didi

rust - 无法导出 stdcall 方法

转载 作者:行者123 更新时间:2023-11-29 08:17:33 26 4
gpt4 key购买 nike

我正在编写一些使用 jni 的代码。我的目标平台是 Windows。所以我的 jni 函数必须使用 stdcall 调用约定,但 Rust 仅使用 cdecl 调用约定导出函数。
我使用 MinGW(可能很重要)

我写了两个函数:

#[no_mangle]
pub unsafe extern "C" fn exported_cmethod(env: &JNIEnv, obj: jobject, path: jstring) {
// Some jni staff
}

#[no_mangle]
pub unsafe extern "stdcall" fn exported_stdmethod(env: &JNIEnv, obj: jobject, path: jstring) {
// Some jni staff
}

然后我使用 dumpbin 查看导出表

dumpbin /exports acc_check.dll | findstr exported
2094 82D 000014A0 exported_cmethod = __ZN4core3fmt5Write10write_char17h774b1da469bdbfa3E

所以你可以看到 Rust 导出了 C 方法但没有导出 stdcall 方法

我做错了什么?

最佳答案

所以我想出了解决这个问题的方法。
我在 MinGW 中使用了 gnu 工具链,这是一个错误。我刚刚用 Microsoft SDK 下载了 MSVC 工具链,它解决了我的问题。

关于rust - 无法导出 stdcall 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57840984/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com