extern "C" has no effect in msvc++ 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?
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.
精彩评论