test.c
# Include
# Include
# Include
# Include
# Include
jstring Java_com_test_b_hello_hellostr (JNIEnv * env, jobject thiz)
{
return (* env) -> NewStringUTF (env, "Hello from JNI!");
}
This compilation is OK.
But why do I put this into test.cpp,
Compile errors.
libb / jtest.cpp: In function '_jstring * Java_com_test_b_hello_hellostr (JNIEnv *, _jobject *)':
jtest.cpp: 108: error: base operand of '->' has non-pointer type '_JNIEnv'
make [1]: *** [. out / .. / obj / SHARED_LIBRARIES / libdrvb_intermediates / jtest.o] Error 1
Why? cpp and c there is such a difference?
View the jni.h file system (alps \ dalvik \ libnativehelper \ include \ nativehelper \ jni.h)
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
...
void (* ReleaseStringChars) (JNIEnv *, jstring, const jchar *);
jstring (* NewStringUTF) (JNIEnv *, const char *);
jsize (* GetStringUTFLength) (JNIEnv *, jstring);
...
jstring NewStringUTF (const char * bytes)
{Return functions-> NewStringUTF (this, bytes);}
.....
Reply:
After you change the cpp, corresponding Android.mk should be changed in xx.cpp
Reply:
Also in the above methods plus
extern "C"
Reply:
Android.mk has changed cpp's.
There are also a plus in front of test.cpp these extern "C"
# Include
# Include
# Include
# Include
# Include
# Ifdef __ cplusplus
extern "C" {
# Endif
# Include "test.h"
# Ifdef __ cplusplus
}
# Endif
No experts know the reason?
Reply:
Experts try ah. Try to compile a look.
Reply:
I tried it out. cpp, we wanted to change env-> (xxx) on the line, c must be a (* env) -> (env, xxx).
The truth?
Reply:
Oh, yes
Reply:
c call gcc cpp g+ + seems to be calling like this series
Reply:
Parameter is not the same type of function
Reply:
Can specifically talk about how different?
Reply:
jni.h have this statement
struct _JNIEnv;
struct _JavaVM;
typedef const struct JNINativeInterface * C_JNIEnv;
# If defined (__cplusplus)
typedef _JNIEnv JNIEnv;
typedef _JavaVM JavaVM;
# Else
typedef const struct JNINativeInterface * JNIEnv;
typedef const struct JNIInvokeInterface * JavaVM;
# Endif
c + + is implemented by the struct _JNIEnv, you can go to the next _JNIEnv realization, we can understand
Reply:
Landlord, I do not understand? You this. C and. Cpp in the end should be how to do? Android.mk compared. C What should be added? Application.mk compared. C What should be added?
Reply:
There prawns passing saw to help me get down ah. QQ547139397
Tears
Reply:
Why I can compile. C file but can not compile. Cpp file ah? ? # Include jni.h front are still a question mark? Help!
Reply:
If c program, use (* env) ->
If it is C + + use env->
There is a difference, here is an example:
c: (* env) -> FindClass (env, "java / lang / ClassLoader");
c + +: env-> FindClass ("java / lang / ClassLoader");
No comments:
Post a Comment