Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4028075

System.loadLibrary() doesn't work under java_g

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.1
    • hotspot
    • sparc
    • solaris_2.5



      Name: laC46010 Date: 01/26/97



      "java_g" fails to load shared library when "java" works fine.
      See test below.

      To run the test, set environment variables JH (Java home) and CC (C compiler)
      and run "jnirun" script.

      Log:

      csh -x jnirun
      setenv JH /export/ld32/jdk_1.1
      setenv CC /export/ld4/set/dist/sparc-S2/SC4.2/bin/cc
      /export/ld32/jdk_1.1/bin/javac -d . Test.java
      /export/ld4/set/dist/sparc-S2/SC4.2/bin/cc -KPIC -G -I/export/ld32/jdk_1.1/include -I/export/ld32/jdk_1.1/include/solaris -o libtest.so dfcl00101.c
      setenv LD_LIBRARY_PATH .:/opt/SUNWspro/lib:/usr/openwin/lib:/usr/ucblib
      setenv CLASSPATH .
      echo =================== Running java pack.Test
      =================== Running java pack.Test
      /export/ld32/jdk_1.1/bin/java pack.Test
      Before loadLibrary
      After loadLibrary
      nativefunc works!!!
      echo =================== Running java_g pack.Test
      =================== Running java_g pack.Test
      /export/ld32/jdk_1.1/bin/java_g pack.Test
      Before loadLibrary
      !!!java.lang.UnsatisfiedLinkError: no test in shared library path:no test in shared library path
      Exception caught: java.lang.UnsatisfiedLinkError: nativefunc
      echo .:/opt/SUNWspro/lib:/usr/openwin/lib:/usr/ucblib
      .:/opt/SUNWspro/lib:/usr/openwin/lib:/usr/ucblib
      /export/ld32/jdk_1.1/bin/java -version
      java version "JDK1.1U"
      uname -r
      5.5


      ::::::::::::::
      jnirun
      ::::::::::::::
      #!/usr/bin/csh

      #setenv JH /export/ld32/jdk_1.1
      #setenv CC /export/ld4/set/dist/sparc-S2/SC4.2/bin/cc

      $JH/bin/javac -d . *.java
      $CC -KPIC -G -I$JH/include -I$JH/include/solaris -o libtest.so *.c
      setenv LD_LIBRARY_PATH ".:$LD_LIBRARY_PATH"
      setenv CLASSPATH .
      echo "=================== Running java pack.Test"
      $JH/bin/java pack.Test
      echo "=================== Running java_g pack.Test"
      $JH/bin/java_g pack.Test

      echo $LD_LIBRARY_PATH
      $JH/bin/java -version
      uname -r

      ::::::::::::::
      dfcl00101.c
      ::::::::::::::
      /* Ident: %Z%%M% %I% %E% */
      /* Copyright %G% Sun Microsystems, Inc. All Rights Reserved */

      #include <stdio.h>
      #include "jni.h"

      #ifdef __cplusplus
      extern "C" {
      #endif

      JNIEXPORT jint JNICALL
      Java_pack_Test_nativefunc(JNIEnv *env, jobject obj)
       {
        puts("nativefunc works!!!");
      return 1;
       }
      #ifdef __cplusplus
      }
      #endif

      ::::::::::::::
      Test.java
      ::::::::::::::
      // Ident: %Z%%M% %I% %E%
      // Copyright %G% Sun Microsystems, Inc. All Rights Reserved

      package pack;
      public class Test {

        public native int nativefunc();

        static {
          try {
            System.out.println("Before loadLibrary");
            System.loadLibrary("test");
            System.out.println("After loadLibrary");
          } catch ( UnsatisfiedLinkError e ) {
            System.out.println("!!!" + e + ":" + e.getMessage());
          }
        }

        public static void main(String argv[])
        {
          Test tob = new Test();

          try {
            int res = tob.nativefunc();
          } catch (Throwable e) {
            System.out.println("Exception caught: "+e);
          }
        }
      }

      ======================================================================

            sliangsunw Sheng Liang (Inactive)
            leosunw Leo Leo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: