Technical article 115102

How do I compile a C/C++ program that references Java 1.2.2 code on OpenServer 5.0.x?

OpenServer 5.0.5OpenServer 5.0.6

Written · Last revised

Problem

I want to call Java code from my C/C++ program. What do I need in order to get this to work properly on OpenServer 5.0.x?

Some sample code of what this might look like is shown below: (JavaClass is the name of your Java class)

# include <jni.h>
# include <stdlib.h>
main() {
          JNIEnv *env;
          JavaVM *jvm;
          JDK1_1InitArgs vm_args;
          jclass cls;
JNI_GetDefaultJavaVMInitArgs(&vm_args);
res = JNI_CreateJavaVM(&jvm,(void **)&env,&vm_args);

cls=(*env)->FindClass(env,"JavaClass"); if(cls==0) printf("No Class Found\n"); else printf("Class Found...\n"); (*jvm)->DestroyJavaVM(jvm);

}

Solution

This requires the UDK Feature Supplement 7.1.1b, the Java Developer Kit 1.2.2 and the appropriate compile line.

The UDK Feature Supplement 7.1.1b and the JDK 1.2.2 for SCO OpenServer 5 is available from SCO at the following URL:

http://wdb1.sco.com/clbk_web/owa/dwn_customer

These two products do require a license.

The correct compile line will vary greatly depending upon what you have included and require for your C/C++ program to function properly. Be sure you are using the correct compiler as well, /udk/usr/ccs/bin/cc is the correct one to use.

The following options must be present in your compile line:

/udk/usr/ccs/bin/cc -I /usr/java2/include -I /usr/java2/include/unixware/ \ -L/usr/java2/jre/lib/x86at/classic -L/usr/java2/jre/lib/x86at \ -L/usr/java2/jre/lib/x86at/green_threads \ -ljava -ljvm -lhpi -o <object_file> <file.c>

You must also set your LD_LIBRARY_PATH to the correct path:

LD_LIBRARY_PATH=/usr/java2/jre/lib/x86at:/usr/java2/jre/lib/x86at/classic:/usr/j
ava2/jre/lib/x86at/green_threads
export LD_LIBRARY_PATH
There have been many modifications to the UDK in the Feature
Supplement 7.1.1b.  Without this Supplement installed, you may see
such errors as:

i386ld values-xa.o: can't find library libjava.a i386ld values-xa.o: can't find library libjvm.a

OR
undefined symbols:
libc_sigunlock _
libc_siglock

See also

For an overview of the Java Native Interface (JNI), please visit the following URL:

http://java.sun.com/docs/books/tutorial/native1.1/concepts/index.html

From the Xinuos technical article database, record 115102. Reproduced with permission. The original is at www.sco.com/ta/115102, which is reachable but blocked from search engines.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.