undefined reference to `clone'

295 views
Skip to first unread message

Y.Y.

unread,
Oct 26, 2011, 10:48:07 PM10/26/11
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!

wolftag

unread,
Oct 31, 2011, 8:27:42 PM10/31/11
to android-ndk
I happened to notice this in the $NDK/docs/system/libc/CHANGES.html of
ndk r6b:

- add clone() implementation for ARM (x86 and SH-4 not working
yet).

Yi YANG

unread,
Nov 1, 2011, 10:51:20 PM11/1/11
to andro...@googlegroups.com
Thanks for your information!


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.




--
Best Regards!
Yi

Reply all
Reply to author
Forward
0 new messages