外部“C”对 msvc 没有影响++ 9.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.
这是 __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.