外部“C”对 msvc 没有影响++ 9.0

发布于 2024-08-25 16:32:32 字数 515 浏览 5 评论 0原文

我管理两个编译器的 JNI 项目:MSVC++ 8.0 和 9.0, 我的 cpp 文件包含以下实现: 外部“C”{ JNIEXPORT jlong​​ JNICALL Java_context_ServiceProviderContext_StartServiceProvider (JNIEnv * env, jclass, jstring jspath){ …… 在depends.exe实用程序的帮助下,

我可以看到MSVC 8.0成功导出了预期的函数:Java_context_ServiceProviderContext_StartServiceProvider 但是在 MSVC 9.0 下编译让我抓狂,它的导出就像完全忽略 extern "C" 一样。 depends.exe 向我展示: _Java_context_ServiceProviderContext_StartServiceProvider@12

有谁知道 9.0 项目中到底是什么导致了这种行为?

I manage project for JNI for both compilers: MSVC++ 8.0 and 9.0,
my cpp file contains following implementation:
extern "C" {
JNIEXPORT jlong JNICALL Java_context_ServiceProviderContext_StartServiceProvider
(JNIEnv * env, jclass, jstring jspath){
.....
}

With help of depends.exe utility I can see that MSVC 8.0 successfully exports function as it is expected: Java_context_ServiceProviderContext_StartServiceProvider
But compiling under MSVC 9.0 gets me crazy it exports like ignoring extern "C" at all. depends.exe shows me: _Java_context_ServiceProviderContext_StartServiceProvider@12

Does anybody know what exactly in 9.0 project that causes this behavior?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘寄 2024-09-01 16:32:32

JNICALL 可能是#define JNICALL __stdcall。更改调用约定将修复名称装饰,但它会严重(包括默默地)破坏 JNI,因为它将调用一个假设 __stdcall 的函数并获取其他内容。

难道真的不起作用吗?从我在谷歌上搜索到的信息看来,JVM 知道如何正确地修饰函数名称。

JNICALL is probably #define JNICALL __stdcall. Changing the calling convention will fix the name decoration, but it will horribly (including silently) break JNI, as it will be calling a function assuming __stdcall and getting something else.

Does it actually not work? From what I can google it seems that the JVM knows how to decorate the function names properly.

缪败 2024-09-01 16:32:32

这是 __stdcall 调用约定;你需要__cdecl。也许尝试将 __cdecl 添加到函数的定义中?

或者,更改项目设置中的默认调用约定。

That's __stdcall calling convention; you need __cdecl. Maybe try adding __cdecl to your function's definition?

Alternatively, change the default calling convention in the project settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文