Extern "C" does not affect msvc ++ 9.0

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

Using the depend.exe utility, I see that MSVC 8.0 successfully exports the function, as expected: Java_context_ServiceProviderContext_StartServiceProvider But compiling under MSVC 9.0 drives me crazy, it is exported as ignoring extern "C" in general. depends.exe shows me: _Java_context_ServiceProviderContext_StartServiceProvider @ 12

Does anyone know what exactly in project 9.0 causes this behavior?

+3
source share
2 answers

JNICALLprobably #define JNICALL __stdcall. Changing the calling convention will correct the name decoration, but it will be terrible (including silently) to break the JNI, because it will call the function that assumes __stdcall, and get something else.

Does it really not work? From what I can do with Google, it seems that the JVM knows how to properly decorate function names.

+1
source

This is the __stdcall calling convention; you need __cdecl. Perhaps try adding __cdecl to the function definition?

Alternatively, change the default usage agreement in the project settings.

0
source

Source: https://habr.com/ru/post/1737380/


All Articles