Click here to Skip to main content
15,877,966 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I’m taking C++/CLI for a spin, and I’ve run into an annoying warning:
JNIEnvWrapper.obj : warning LNK4248: unresolved typeref token (0100000C) for '_jmethodID'; image may not run
JNIEnvWrapper.obj : warning LNK4248: unresolved typeref token (0100000D) for '_jfieldID'; image may not run

#pragma managed(push,off)
struct JNIEnv_;
typedef JNIEnv_ JNIEnv;

struct JavaVM_;
typedef JavaVM_ JavaVM;

struct _jfieldID;
typedef _jfieldID *jfieldID;
struct _jmethodID;
typedef _jmethodID *jmethodID;

/* .. code removed ...*/

#pragma managed(pop)

Replacing the section above with
#pragma managed(push,off)
#include <jni.h>
#pragma managed(pop)

doesn't solve the problem either ...

Neither does
#pragma warning( disable : 4248 )

Oddly enough I'm not getting any warnings about JNIEnv_ or JavaVM_.
I'm just using jmethodID and jfieldID in managed code.

jmethodID FromReflectedMethod(JavaObject^ method);
jfieldID FromReflectedField(JavaObject^ field);

jmethodID JNIEnvWrapper::FromReflectedMethod(JavaObject^ method)
	jmethodID result = 0;
	jobject jObj = method->JNINative;
	result = env->FromReflectedMethod(jObj);
	return result;
jfieldID JNIEnvWrapper::FromReflectedField(JavaObject^ field)
	jfieldID result = 0;
	jobject jObj = field->JNINative;
	result = env->FromReflectedField(jObj);
	return result;

So _jfieldID and _jmethodID are treated as opaque types. (As I'm not playing around with the internals of the JDK, they could hardly be anything else.) The code seems to run just fine, but I would like to get rid of the warnings - they are usually there for a reason :).

Any ideas? I'll be happy to just find a way to suppress the warning ...

Espen Harlinn
Updated 12-Jan-17 16:45pm
Sergey Alexandrovich Kryukov 27-Feb-11 19:20pm    
Good question, by the way.
Espen Harlinn 27-Feb-11 19:29pm    
Thanks - I'll be delighted if it can be solved :)

Did you see this thread:[^]?

I think there is a reasonable explanation there. You case looks similar to the case on incomplete structure in one of the examples. It's mentioned that the warning disappears when they remove
"/clr". I understand you need CLR flag, but do you observer the same? JNI is unmanaged, so the warning should disappear if you remove the flag, just for experiment.

Share this answer
Espen Harlinn 27-Feb-11 19:23pm    
Yepp, I'm just looking for a way to get rid of the warning for now, as I imagine I'll get quite a few downvotes for posting code that doesn't compile "cleanly" ;->

I can't remove the /clr option as I'm creating a library, JNI4Net, that integrates .Net and JNI ...
Sergey Alexandrovich Kryukov 27-Feb-11 19:29pm    
Such down-vote would be stupid as you clearly state that the inability to compile without the warning...

Espen, I said in first place you cannot remove "/clr". I only ask you if you can leave only managed code, temporarily, and make sure the warnings depend on "/clr". Could you?

Espen Harlinn 27-Feb-11 19:37pm    
Most of the code comes from various other works that compiles without a hitch; this has to do with incomplete types and clr, as I’d like to avoid including the “jni.h” header as part of the public interface for the library.
Sergey Alexandrovich Kryukov 27-Feb-11 19:35pm    
By the way, does pragma suppress works for you? You see, I suspect you may always get the warning...
However, another idea: could you create a fake fully defined structure for this purpose? It will be correct from the CLR standpoint, and the structure will not be used with JNI, because linked functions from JNI will need only a pointer? Do you understand the idea?
Espen Harlinn 27-Feb-11 19:42pm    
#pragma suppress doesn't seem to exist, and this didn't work either:
#pragma warning( disable : 4248 )
"So, how about fake structure?"

Sergey Alexandrovich, it works well :-)

Thank you! :-)
Share this answer
edit jni.h file chang frome "struct _jfieldID" to "struct _jfieldID {}"
Share this answer
Dave Kreskowiak 12-Jan-17 23:34pm    
You're a bit late to the party. This question was asked SIX YEARS AGO. Your answer doesn't really add anything to the now non-existent discussion.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900