Native Code Entry Point

Hi All,
I have a native .so file and I need to do some Initialization when the
user uses this native code.For that I used the jint
JNI_OnLoad(JavaVM *vm, void *reserved) function and it is sucess in
QNX6.1 in x86.
Now I am builing the native code for ARM(complier option
“-Vgcc_ntoarmle” )processors. In that case I need to rebuild and make
the j9 linked with my natives call statically
(I can’t find a shared object method for ARM).
I successfully rebuild the j9 and all my native calls are calling
correctly.
Only thing is that i won’t call my init while
loadLibaray.(JNI_OnLoad).I think it is due to static build.
So is there any other method for the init().
I tried the following

void initialize() __attribute ((constructor));
void initialize ()
{
printf ("in init);
}
This code worked, But when I enter simply j9 ( without class), this
message is printed first and then the it gives the error(that no
ClassDefFound).
So I think this not a better method…
So please help me on this…

My customer is not willing to call a seperate function for
Initializing the native code.So please suggest a way…
Is there any entry point for the libaray as we have WinMain() in
windows.

Regards
Shibu Baby

Hi

I don’t know about this compiler feature/hack, but you can have a portable
way to do this thing… if you’re ready to use about 10 lines of C++. Just
rename your file with extension .cc and make following modifications-

// old version file.c

// my existing function
void foo()
{

}
void myinitfunction()
{

}


// new version file.cc
//--------------------
extern “C” {
// my existing function
void foo()
{

}

void myinitfunction()
{

}

} // end of extern “C” block

static class FooInit
{
public:
FooInit()
{
printf(“In Init”);
myinitfunction();
}

// extra benefit…
~FooInit()
{
printf(“In finish”);
// call some cleanup routine if you have one
}
} myFooInit;
//------------------------------------------------------

C++ language will guarantee that initialization will always be done
irrespective of compiler/platform.
The ‘extern “C”’ Block will ensure that your C functions continue to
compiler/work/link as they would if compiled by C compiler (C++ name
mangling is a bit different, extern “C” provides standard C naming).

HTH

Regards

Hi All,
I have a native .so file and I need to do some Initialization when the
user uses this native code.For that I used the jint
JNI_OnLoad(JavaVM *vm, void *reserved) function and it is sucess in
QNX6.1 in x86.
Now I am builing the native code for ARM(complier option
“-Vgcc_ntoarmle” )processors. In that case I need to rebuild and make
the j9 linked with my natives call statically
(I can’t find a shared object method for ARM).
I successfully rebuild the j9 and all my native calls are calling
correctly.
Only thing is that i won’t call my init while
loadLibaray.(JNI_OnLoad).I think it is due to static build.
So is there any other method for the init().
I tried the following

void initialize() __attribute ((constructor));
void initialize ()
{
printf ("in init);
}
This code worked, But when I enter simply j9 ( without class), this
message is printed first and then the it gives the error(that no
ClassDefFound).
So I think this not a better method…
So please help me on this…

My customer is not willing to call a seperate function for
Initializing the native code.So please suggest a way…
Is there any entry point for the libaray as we have WinMain() in
windows.

Regards
Shibu Baby