tags:

views:

58

answers:

2

Hey everyone,

I'm working with JNI on a current project, and am getting a strange error from my C++ code during compilation. I get an error stating:

error: overloaded function with no contextual type information

This is coming from the "nativegetsupportedciphersuites" line in the following array, which is mapping java functions with their C++ counterparts. I've cut out the other array members to make it easier to read.

static JNINativeMethod sSocketImplMethods[] =
{
...
    {"nativegetsupportedciphersuites", "()[Ljava/lang/String;", (void*)&Java_mypackage_SocketImpl_nativegetsupportedciphersuites},
...
};


I think it must be an error with the type declaration, but really have no clue. The type declaration was generated by the javah function, so I assume it is correct. The function signature of the above method is shown below:

JNIEXPORT jobjectArray JNICALL Java_mypackage_nativegetsupportedciphersuites(JNIEnv* env, jobject object)


Any Thoughts?

Chris

+1  A: 

The error message indicates that you method is overloaded. The compiler can't figure out which one of the overloads you want to take a pointer to, since it doesn't have any parameter information.

It sounds like you didn't intend to overload the method. Do you have a second declaration of that method anywhere? Are you using the exact same signature in both the header and the body?

JSBangs
Thanks JSBangs! I had a slight difference in my header declaration.
Chrisc
A: 

Generally, you shouldn't cast function pointers to void* - some platforms can't fit a function pointer in a void*. The generic function pointer type is 'void (*)()', though obviously you must cast back to the correct type before calling the function to avoid stack corruption.

The error suggests that there might be two different overloads for Java_mypackage_nativegetsupportedciphersuites visible (perhaps because the signature in your .cpp file doesn't exactly match that in the javah generated .h file), and hence it can't choose the one you want based on the type you are casting to (which is just void*).

Have you got 'extern "C"' correctly in place in the source file?

TomW