This document refers to the o32/n32 MIPS ABI's and the green/native threads packages. These concepts, and their associated environment variables and command-line options, are described in MIPS ABI's and Threads.
The description below assumes that you have installed Java in the
default location. If you used the -r
option to
inst or swmgr to install Java in an alternate location,
then you should prepend that location to all instances of
/usr/java
below.
In the sections that talk about building applications, it is
assumed that you have installed the necessary subsystems from the
java_dev
product.
For general information on developing applications with native code, and for detailed information on the new Java Native Interface (JNI), see Sun's JNI documentation. An easy way to get started is with our JNI demos. The main points to remember are:
-o32
/-n32
command-line options or to
set the SGI_ABI
environment variable (it controls these
compilers as well as the Java software).
/usr/java/include
and /usr/java/include/irix
.
-shared
flag to create a DSO.
/usr/java/lib/sgi/green_threads
/usr/java/lib32/sgi/green_threads
Note that simply linking against the green threads libraries is
fine, regardless of whether the application will be run with green
threads or native threads. Use the -l
option
with the name of any library you need to link against.
For example, if javah produces a stub file
HelloWorld.c
and you provide native routine implementations
in HelloWorldImp.c
, you might use the following commands to
create an n32 DSO libhello.so
:
cc -n32 -I/usr/java/include -I/usr/java/include/irix -c HelloWorld.c cc -n32 -I/usr/java/include -I/usr/java/include/irix -c HelloWorldImp.c cc -n32 -shared HelloWorld.o HelloWorldImp.o -L/usr/java/lib32/sgi/green_threads -ljava -Wl,-woff,85 -Wl,-woff,134 -o libhello.so
(the -Wl,-woff,85 -Wl,-woff,134
options simply filter
out some harmless warnings that are typical when linking against
libjava.so
). You could then load this DSO with the Java
call:
System.loadLibrary("hello");
To run a Java application with native code, you need to set your
LD_LIBRARY_PATH
or LD_LIBRARYN32_PATH
(depending on which ABI the native code DSO's were compiled for) as
described in setting up your environment to
run Java correctly. Then make sure to run java with the
correct ABI as well.
To determine the ABI of any object file, DSO, or executable, simply
run the UNIX file(1)
command on it. For example:
file libhello.so
If the resulting message begins with "ELF
32-bit
", the file is o32. If the resulting message begins
with "ELF N32
", the file is n32.
The Invocation API is a part of Sun's Java Native Interface which allows you to create C/C++ applications with embedded Java virtual machines for running Java code. For more information, see the Invocation API section of the JNI specification under Sun's JNI documentation.
Building a C/C++ application which uses the Invocation API is
generally similar to building a native code DSO for a Java
application, except that you use the compilers to create an executable
instead of a DSO, so you do not need the -shared
flag.
Running an Invocation API application is different from running a
Java application, however, because what is run is a C/C++ executable
rather than one of the Java command scripts. This means that the
locations of the system classes and DSO's will not be automatically
inserted into your CLASSPATH
and
LD_LIBRARY_PATH
/LD_LIBRARYN32_PATH
.
If you have received from another source an Invocation API application which does not account for this, or you want to run (and possibly distribute for others to run) an Invocation API application that you have written, the best way to handle this is to run the program using a script which sets these environment variables properly and then runs the executable. The correct class path fragment to locate all the system classes is
/usr/java/classes:/usr/java/lib/rt.jar:/usr/java/lib/i18n.jar
and the correct DSO locations depend on the ABI and threads package you are using:
/usr/java/lib/sgi/green_threads
/usr/java/lib32/sgi/green_threads
/usr/java/lib/sgi/native_threads
/usr/java/lib32/sgi/native_threads
See our Invocation API demo
for an example of how to do this (if you have installed the necessary
subsystems from the java_dev
product).
Java and other Java-based names are trademarks of Sun Microsystems, Inc., and refer to Sun's family of Java-branded technologies. Sun, Sun Microsystems, and the Sun Logo are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.