HP-UX Programmer's Guide for Java 2

Table Of Contents
void _main();
}
JNIEXPORT void JNICALL
Java_TestJava2CallingNative_initialize(JNIEnv *, jclass)
{
_main();
}
JNIEXPORT void JNICALL
Java_TestJava2CallingNative_sayHelloWorld(JNIEnv *, jclass)
{
cout << "aC++ says HelloWorld via iostreams"
<< endl;
}
In the above example you can see that the additional native method initialize()
simply calls the routine _main(). Since the Java™ Native interface does not allow us
to call a routine name _main directly we have to write this wrapper function to allow
us to call _main indirectly. Also note that we need to use initialization extern "C" to
direct the C++ compiler not to perform name mangling on this routine. The entry point
_main is located in the PA-RISC version of the C++ runtime support library
libCsup.sl.
NOTE: As mentioned above, the additional initialization step is no longer necessary
with the Integrity version of HP aC++. In fact calling _main from code compiled by
the Integrity version of HP aC++ will result in _main being an unresolved symbol.
Compile this C++ source file:
$ aCC +z +u4 -c -mt -I<java_dir>/include \
-I<java_dir>/include/hp-ux aCCImpl.C
Output:
aCCImpl.o
Create the shared library containing the native method implementation:
PA-RISC:
PA-RISC:
$ aCC -b -o libaCCImpl.sl aCCImpl.o \
-lstd -lstream -lCsup -lm
(see below for Integrity)
Output:
libaCCImpl.sl
(libaCCImpl.so on Integrity)
Note that the C++ driver program aCC must be used to create the shared library. Also
note that an explicit dependency on three C++ runtime libraries need to be specified.
The HP aC++ compiler has split the -AP runtime support libraries into three separate
shared libraries: libCsup.sl, libstream.sl and libstd.sl (libCsup.so,
libstream.so and libstd.so on Integrity). For more information on Linking Your
Java™ calling a native (non-Java) method 51