开发者

extern "C" has no effect in msvc++ 9.0

开发者 https://www.devze.com 2022-12-23 10:53 出处:网络
I manage project for JNI for both compilers: MSVC++ 8.0 and 9.0, my cpp file contains following implementation:

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号