The next few sections explain the procedure for creating a shared object with native methods which can later be dynamically loaded by the Java VM.
Compilation of source code
To compile the C source code of Java native methods, the C/C++ compiler as of V3.0B must be used for the parts of the source code which work with the JNI.
When compiling the C or C++ parts, it is essential that the following compiler options are used:
-I <Installation path>/include
This option is necessary in order that the Java distribution header files are found. For <Installation path> the path in which JENV has been installed must be substituted. For a standard installation, this is /opt/java/jdk-9.0.4. Refer to the Release Notice for the currently valid name.
-K workspace_stack
This is necessary in order that the Garbage Collector can also find the Java objects used in the C parts and that the objects can be thread-safe.
-K c_names_unlimited
This is necessary in order that the name mangling correctly functions for native interface functions.
-K llm_keep
This is necessary in order that the name mangling correctly functions for native interface functions and that the runtime system functions are found.
-K llm_case_lower
This is necessary in order that the name mangling correctly functions for native interface functions and that the runtime system functions are found.
-D __SNI_THREAD_SUPPORT
This option is mandatory for C++ compilations.
The following compiler options can be useful:
-K ieee_floats
Used when you want the IEEE format for floating point numbers to also be used in the C code.
-K literal_encoding_ascii
-K literal_encoding_ascii_full
Used when you want to use ASCII strings in the C code.
-K enum_long
Should always be set, as the default setting does not conform to the ANSI standard.
Furthermore, it is essential that compilation is performed in ANSI mode (-Xa or -Xc).
Linking a main module
If the implementation of a shared object is to consist of several modules, then these should be linked together into a main module. This is done using the command cc or c89, where the following options must be specified
-r
This option has the effect of linking a main module without adding any standard libraries like (CRTE). Under no circumstances should these be explicitly linked to it with -lc or -lsocket.
-B llm4
This option cause the linker to create a main module in LLM4 format which is necessary for the long name of the Java native methods.
Creating an LMS library
The main module created (and held in the POSIX file system) must be stored in a PLAM library as an element with the element type L. The best way to do this is with the POSIX command bs2cp, which also creates the library if it does not yet exist.
It is quite in order for several shared objects to be stored in such a PLAM library
Creating the object description
To create the necessary description file for a shared object, the command mk_shobj is available. The command pr_shobj is used to view the content of such a description file. Both commands are part of the Java distribution and are described in detail in chapter "Commands for BS2000".
C++ objects must be labeled as such (see subsection "Options" of section "mk_shobj").