zenoname
unread,Nov 5, 2009, 3:16:00 AM11/5/09Sign 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
Hello,
(first sorry I posted the same message in the android developer group
but as it doesn't appear I post it in the NDK group as it is more
related to it)
I'm trying to create a simple project with the Android NDK.
I created a jni library which is calling a function from a shared C*
library.
I make it work with a C library but as soon as I try with a C++
library it crashes (when calling the c++ function)
As many posts I read I suspect a name mangling problem but whatever I
tried it doesn't change the problem
Here is a summary of what I've done : I created a jni library linking
two simple libs (jnilib my jni interface with java, libtoto.so my c
library, libtotocpp.so my cpp lib). The c* libs simply export a
function returning a int. If I call GetNumber() form the C lib no
problem. If I call the GetNumberCPP() from my C++ lib it crashes
Here are the code and compilation stuffs.
If anyone could tell me what's wrong that would be very very cool :)
Thanks.
- jnilib.c (arm-eabi-gcc -shared jnilib.c -o libjnilib.so libtoto.so
libtotocpp.so -nostdlib -Bdynamic)
Here if I don't call GetNumberCPP() all works
#include "toto.h"
#include "toto.hpp"
#ifdef _cplusplus
extern "C"
{
#endif
jstring Java_amob_jnscapi_jnscapi_initserver (JNIEnv* env,
jobject thiz )
{
char version[50];
sprintf(version,"%d %d",GetNumberC(),GetNumberCPP());
return (*env)->NewStringUTF(env, version);
}
#ifdef _cplusplus
}
- libtoto.so (arm-eabi-gcc -shared toto.c -o libtoto.so -nostdlib -
Bdynamic)
#include "toto.h"
int GetNumberC()
{
return 33;
}
- libtotocpp.so (arm-eabi-g++ -shared toto.cpp -o libtotocpp.so -
nostdlib -Bdynamic)
#include "toto.hpp"
#ifdef _cplusplus
extern "C"
{
#endif
int GetNumberCPP()
{
return 56;
}
#ifdef _cplusplus
}
#endif
- In my java class I tried to load all libs ...
System.loadLibrary("totocpp");
System.loadLibrary("toto");
System.loadLibrary("jnilib");