Why is jni.j installed in ${prefix}/include?

Martin Kahlert martin.kahlert@infineon.com
Thu Jan 10 06:48:00 GMT 2002


Hi, this is a complaint.

I got bitten by this (OS is Linux):
I installed gcc-3.0.3 (with its java support) without giving a prefix,
so i ended up with a jni.h installed into /usr/local/include.

After that it played with gcc-20020107 with --prefix=/sw/gcc-3.1
ending up with a second and incompatible /sw/gcc-3.1/include/jni.h.

Then i tried JNI, so i #included <jni.h>, which is found from 
/usr/local/include. It took me some time to track that down, though.

So: Why isn't jni.h installed into
${prefix}/lib/gcc-lib/i686-pc-linux-gnu/3.1/include?
Since it changes that often it would make sense to treat it as
a very compiler dependent file which belong to exactly one version.

Thanks for any clarification.

Unfortunately, JNI seems to not work in 20020107.
At least gdb tells me, that the variables i pass to NewStringUTF are changed 
into completely unrelated things, but this is not reproduceable.

I am now doing a full bootstrap with 20020107 again and without a
/usr/local/include/jni.h. Perhaps that helps.

Here is my source if anybody would like to try it:

$ cat chello.c
#include <jni.h>
#include <stdio.h>

#define PATH_SEPARATOR ':'

#define USER_CLASSPATH "." /* where Prog.class is */

int main()
{
 JNIEnv *env;
 JavaVM *jvm;
 JavaVMInitArgs vm_args;
 jint res;
 jclass cls;
 jmethodID mid;
 jstring jstr;
 jobjectArray args;
 char classpath[1024];

 vm_args.version = JNI_VERSION_1_2;

 JNI_GetDefaultJavaVMInitArgs(&vm_args);

 /* Create the Java VM */
 res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
 if (res < 0)
    {
     fprintf(stderr, "Can't create Java VM\n");
     exit(1);
    }

 cls = (*env)->FindClass(env, "hello");
 if (cls == 0) {
     fprintf(stderr, "Can't find hello class\n");
     exit(1);
 }

 mid = (*env)->GetStaticMethodID(env, cls, "main", "([Ljava/lang/String;)V");
 if (mid == 0) {
     fprintf(stderr, "Can't find Prog.main\n");
     exit(1);
 }

 jstr = (*env)->NewStringUTF(env, " from C!");
 if (jstr == 0) {
     fprintf(stderr, "Out of memory\n");
     exit(1);
 }
 args = (*env)->NewObjectArray(env, 1, 
         (*env)->FindClass(env, "java/lang/String"), jstr);
 if (args == 0) {
     fprintf(stderr, "Out of memory\n");
     exit(1);
 }
 (*env)->CallStaticVoidMethod(env, cls, mid, args);

 (*jvm)->DestroyJavaVM(jvm);
}

$ cat hello.java
public class hello
{
 public static void main(String[] args)
    {
     System.out.println("Hello World");
    }
}

Command line i used:
$ gcj -o chello chello.c hello.java

Perhaps that's all only my fault and everything is wonderful after this
bootstrap again.

Bye,
Martin.

-- 
The early bird catches the worm. If you want something else for       
breakfast, get up later.



More information about the Java mailing list