Y.Y.
unread,Oct 26, 2011, 10:48:07 PM10/26/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to android-ndk
Following is a sample based on Android NDK for x86(android-ndk-r6b):
#include <string.h>
#include <sched.h>
#include <jni.h>
/* This is a trivial JNI example where we use a native method
* to return a new VM String. See the corresponding Java source
* file located at:
*
* apps/samples/hello-jni/project/src/com/example/HelloJni/
HelloJni.java
*/
#define FIBER_STACK 8192
void * stack;
int do_something()
{
free(stack);
exit(1);
}
jstring
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
jobject thiz )
{
void* stack;
stack = malloc(FIBER_STACK);
clone(&do_something, (char *)stack + FIBER_STACK, CLONE_VM|
CLONE_VFORK, 0);
return (*env)->NewStringUTF(env, "Hello from JNI!");
}
When above code is compiled, following issues are encountered:
Gdbserver : [x86-4.4.3] libs/x86/gdbserver
Gdbsetup : libs/x86/gdb.setup
Compile x86 : hello-jni <= hello-jni.c
C:/cygwin/home/yyang85/android-ndk-r6b/samples/hello-jni/jni/hello-
jni.c: In function 'do_something':
C:/cygwin/home/yyang85/android-ndk-r6b/samples/hello-jni/jni/hello-
jni.c:32: warning: incompatible implicit declaration of built-in
function 'exit'
SharedLibrary : libhello-jni.so
C:/cygwin/home/yyang85/android-ndk-r6b/samples/hello-jni/obj/local/x86/
objs-debug/hello-jni/hello-jni.o: In function
`Java_com_example_hellojni_HelloJni_stringFromJNI':
C:/cygwin/home/yyang85/android-ndk-r6b/samples/hello-jni/jni/hello-
jni.c:41: undefined reference to `clone'
collect2: ld returned 1 exit status
make: *** [/home/yyang85/android-ndk-r6b/samples/hello-jni/obj/local/
x86/libhello-jni.so] 閿欒 1
It is very strange why the c standard function ‘clone’ is undefined?
It looks there are some issues in libc of android NDK for x86, because
there is no any issue in same level based on ARM.
Thanks!