Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JNI_CreateJavaVM() causes Segmentation Fault

1,053 views
Skip to first unread message

Luke Bertha

unread,
Aug 8, 2001, 10:32:02 AM8/8/01
to
Hi everybody,

I'm working on Solaris Sparc 2.5.1 and trying to invoke the simplest
Java Class HelloWorld from a C++ program. I use jdk 1.3.1 and gcc-2-95
. I got my invoke.cxx from the Sun homepage which causes by running
always Segmentation Fault. I have debugged it already and it crashes
executing JNI_CreateJavaVM. Any idea why?

I tried out other working examples from JNI books but the error stays
the same.

Here what I do:

>gcc -I<all possible include libraries> -L<all poss. libraries> -g
-ljava invoke.cxx -o hello

Compiles and links OK, but in the next step -> segmentation fault:

>hello
Segmentation Fault

I'd appreciate any help!

Luke


My source code:

#include <jni.h>

#define PATH_SEPARATOR ';' /* define it to be ':' on Solaris */
#define USER_CLASSPATH "." /* where Prog.class is */

int main() {
JNIEnv *env=NULL;
JavaVM *jvm=NULL;
jint res;
jclass cls;
jmethodID mid;

JavaVMInitArgs vm_args;
JavaVMOption options[1];
options[0].optionString ="-Djava.class.path=" USER_CLASSPATH;
vm_args.version = 0x00010002;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = JNI_TRUE;
/* 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( "HelloWorld");
if (cls == 0) {
goto destroy;
}

mid = env->GetStaticMethodID(cls,
"main","([Ljava/lang/String;)V");
if (mid == 0) {
goto destroy;
}
env->CallStaticVoidMethod(cls, mid, args);

destroy:
if (env->ExceptionOccurred(env)) {
env->ExceptionDescribe(env);
}
jvm->DestroyJavaVM(jvm);
return 0;
}

Gordon Beaton

unread,
Aug 9, 2001, 3:05:43 AM8/9/01
to
On 8 Aug 2001 07:32:02 -0700, Luke Bertha wrote:
> I'm working on Solaris Sparc 2.5.1 and trying to invoke the simplest
> Java Class HelloWorld from a C++ program. I use jdk 1.3.1 and
> gcc-2-95 . I got my invoke.cxx from the Sun homepage which causes by
> running always Segmentation Fault. I have debugged it already and it
> crashes executing JNI_CreateJavaVM. Any idea why?
>
> I tried out other working examples from JNI books but the error stays
> the same.
>
> Here what I do:
>
> >gcc -I<all possible include libraries> -L<all poss. libraries> -g
> -ljava invoke.cxx -o hello
>
> Compiles and links OK, but in the next step -> segmentation fault:
>
> >hello
> Segmentation Fault
>
> I'd appreciate any help!

Interestingly enough your code really is C, not C++, yet by naming the
file .cxx you are telling gcc to compile it as though it were C++. In
fact you seem to be mixing the two in an odd way.

To call the JNI functions from a C program, do it this way, e.g.:

(*env)->FindClass(env,"HelloWorld");
(*env)->ExceptionOccurred(env);
(*jvm)->DestroyJavaVM(jvm);

From C++, do it this way:

env->FindClass("HelloWorld");
env->ExceptionOccurred();
jvm->DestroyJavaVM();

You are combining these mechanisms when you call ExceptionOccurred(),
and this could be what's causing your problem.

I suggest you decide one way or the other. Also try using -Wall to get
more information from the compiler, because it would have complained
about some of these things (in fact I am unable to compile your code
without making the changes I've suggested).

/gordon

--
[ do not send me private copies of your followups ]
g o r d o n . b e a t o n @ e r i c s s o n . c o m
ericsson research
stockholm, sweden

Luke Bertha

unread,
Aug 9, 2001, 10:22:17 AM8/9/01
to
Hi,

First of all thanks for your reply! I decided for C++ and I've made
the changes you suggested. However I get run-time Bus Error. I tried
with -Wall option but didn't work :
>gcc -g -ljava -Wall -I<..> -L<..> invoke.cxx -o hello

Compiles and links without error but -Wall makes nothing appropriate.
And when I run it->Bus Error.

>hello
Bus Error

What's going on? Thanks in advance!

Luke

My source:

#include <jni.h>

#define PATH_SEPARATOR ';' /* define it to be ':' on Solaris */
#define USER_CLASSPATH "." /* where Prog.class is */

int main() {
JNIEnv *env=NULL;
JavaVM *jvm=NULL;
jint res;
jclass cls;
jmethodID mid;

jobjectArray args;

JavaVMInitArgs vm_args;
JavaVMOption options[1];
options[0].optionString ="-Djava.class.path=USER_CLASSPATH";
vm_args.version = 0x00010002;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = JNI_TRUE;
/* 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( "HelloWorld");
if (cls == 0) {
goto destroy;
}

mid = env->GetStaticMethodID(cls,"main","([Ljava/lang/String;)V");
if (mid == 0) {
goto destroy;
}
env->CallStaticVoidMethod(cls, mid, args);

destroy:
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
}
jvm->DestroyJavaVM();
return 0;
}
not.fo...@see.signature (Gordon Beaton) wrote in message news:<9ktco7$l6a$1...@news.du.uab.ericsson.se>...

Gordon Beaton

unread,
Aug 10, 2001, 2:49:52 AM8/10/01
to
On 9 Aug 2001 07:22:17 -0700, Luke Bertha wrote:
> First of all thanks for your reply! I decided for C++ and I've made
> the changes you suggested. However I get run-time Bus Error. I tried
> with -Wall option but didn't work :
> >gcc -g -ljava -Wall -I<..> -L<..> invoke.cxx -o hello
>
> Compiles and links without error but -Wall makes nothing
> appropriate. And when I run it->Bus Error.

Ok at least this time I could compile your code without errors. And I
can run it too...

But I think your problem is that this variable is never initialized:

> jobjectArray args;

( In your previous version this declaration wasn't present, and was
one of the reasons I had to modify your code to even compile it. )

But here you pass args to this call:

> env->CallStaticVoidMethod(cls, mid, args);

Try initializing args so that it contains some reasonable value.

Also, try printing some messages after the calls to CreateJVM,
FindClass etc even when they succeed, so you'll have a better idea of
where the problem might be.

Luke Bertha

unread,
Aug 13, 2001, 4:04:42 AM8/13/01
to
Hi,

You're right, so I initialized args with NewObjectArray(int, jclass,
jobj) before I use it. I also initialized a jstring type because the
NewObjectArray()function needs a Java object at it's third argument.
I included some printf() functions just before and after the naughty
CreateJVM().
The interesting thing is that whereever I insert my
printf("Anything"); it flies away at runtime with Segmentation Fault
without printing out anything. Why?

Thanks in advance,

Luke

Compile,link, run commands like before. Code:
#include <jni.h>

#define PATH_SEPARATOR ';' /* define it to be ':' on Solaris */
#define USER_CLASSPATH "." /* where Prog.class is */

int main() {
printf("Let's go!");


JNIEnv *env=NULL;
JavaVM *jvm=NULL;
jint res ;
jclass cls;
jmethodID mid;

jstring jstr = env -> NewStringUTF("");
jobjectArray args;

JavaVMInitArgs vm_args;
JavaVMOption options[1];
options[0].optionString ="-Djava.class.path=USER_CLASSPATH";
vm_args.version = 0x00010002;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = JNI_TRUE;
/* Create the Java VM */

printf("Start to create a JVM!");

res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);

printf("JVM have just been created!");


if (res < 0) {
fprintf(stderr, "Can't create Java VM\n");
exit(1);
}
cls = env->FindClass( "HelloWorld");
if (cls == 0) {
goto destroy;
}

args = env-> NewObjectArray(1, cls, jstr);

Gordon Beaton

unread,
Aug 14, 2001, 3:24:42 AM8/14/01
to
On 13 Aug 2001 01:04:42 -0700, Luke Bertha wrote:
> The interesting thing is that whereever I insert my
> printf("Anything"); it flies away at runtime with Segmentation Fault
> without printing out anything. Why?

I have looked only very briefly at your code.

First of all, you can't call env-> functions *before* you've created
the JVM or you will get segfaults every time. This is completely
unrelated to the printf's in your code; env is not initialized until
the call to CreateJavaVM() has succeeded.

Also, in your call to NewObjectArray() the second argument should be
the class that the array should contain i.e. String, not HelloWorld.
I suggest that the array should be of length 0 if you have no
arguments to pass to main(), but don't believe that this is related to
your current problems.

If you continue to get segfaults, you should at least try to run your
code in a debugger such as gdb, so that you can see where the segfault
is occurring.

Luke Bertha

unread,
Aug 14, 2001, 11:19:15 AM8/14/01
to
> Also, in your call to NewObjectArray() the second argument should be
> the class that the array should contain i.e. String, not HelloWorld.
> I suggest that the array should be of length 0 if you have no
> arguments to pass to main(),...

So I have to define a new class containing only one String with length
of 0? What did you mean here actually, it's not quite clear.

Also I ran gdb and here what I got:
(gdb) run hello
Starting program: /home/hello hello
warning: Unable to find dynamic linker breakpoint function.
warning: GDB will be unable to debug shared library initializers
warning: and track explicitly loaded dynamic code.

Program received signal SIGSEGV, Segmentation fault.
0xef5a9358 in strlen ()

Luke

Gordon Beaton

unread,
Aug 14, 2001, 11:53:32 AM8/14/01
to
On 14 Aug 2001 08:19:15 -0700, Luke Bertha wrote:
> > Also, in your call to NewObjectArray() the second argument should be
> > the class that the array should contain i.e. String, not HelloWorld.
> > I suggest that the array should be of length 0 if you have no
> > arguments to pass to main(),...
>
> So I have to define a new class containing only one String with
> length of 0? What did you mean here actually, it's not quite clear.

Since main expects an array of Strings, you should pass it an array of
Strings. If you don't happen to have any arguments you should pass a
0-length array, but it should still be a String array, not a
HelloWorld array as you were doing earlier.

This is how to create a 0-length array of String:

jclass cls = env->FindClass("java/lang/String");
jobjectArray array = env->NewObjectArray(0,cls,NULL);


> Also I ran gdb and here what I got:
> (gdb) run hello
> Starting program: /home/hello hello
> warning: Unable to find dynamic linker breakpoint function.
> warning: GDB will be unable to debug shared library initializers
> warning: and track explicitly loaded dynamic code.
>
> Program received signal SIGSEGV, Segmentation fault.
> 0xef5a9358 in strlen ()

I believe that you are already compiling with "-g" to include debug
information, so just type "bt" to see where you are in the code, i.e.
who called strlen().

Or if you type "gdb hello", then "break main" before "run", you can
use "next" to step through the source one line at a time. I'll refrain
from writing a gdb tutorial here, but there is plenty of information
available if you type "help" or even "help bt", etc.

Note that I was able to successfully run the code you posted on the
9th, after initialising args.

Luke Bertha

unread,
Aug 20, 2001, 8:09:48 AM8/20/01
to
Hi,

thanks for the tipps and sorry for the long reply-time(flu)! I wonder
how you have made the program runnig. Probably you use an other
version of Solaris.(Could you post how did you do it?) I made the
changes you suggested, however I'm afraid the problem could be in
JNI_CreateJavaVM() and Solaris after all.
I debugged the program and it gets segfault at JNI_CreateJavaVM():
>gbd hello
>break main
>run
>next
(I left the first few nexts out for the sake of shortness)
(gdb) next
24 printf("Start to create a JVM!")
(gdb) next
25 res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args)
(gdb) next

Program received signal SIGSEGV, Segmentation Fault.
0xf5a9358 in strlen ()

I am quite surprised because even though the program executes printf
it does not print out anything! I also searched strlen either in the
jdk1.3 or in the gcc include directories but have not found. Where is
it?
Luke

Code:
#include <jni.h>

#define PATH_SEPARATOR ';' /* define it to be ':' on Solaris */
#define USER_CLASSPATH "." /* where Prog.class is */

int main() {
printf("Let's go!");
JNIEnv *env=NULL;
JavaVM *jvm=NULL;
jint res ;
jclass cls;
jmethodID mid;

jstring jstr ;
jobjectArray args;

JavaVMInitArgs vm_args;
JavaVMOption options[1];
options[0].optionString ="-Djava.class.path=USER_CLASSPATH";
vm_args.version = 0x00010002;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = JNI_TRUE;
/* Create the Java VM */
printf("Start to create a JVM!");

res = JNI_CreateJavaVM(&jvm,(void**)&env, &vm_args);


printf("JVM have just been created!");
if (res < 0) {
fprintf(stderr, "Can't create Java VM\n");
exit(1);
}

//cls = env->FindClass( "HelloWorld");


cls = env->FindClass( "java/lang/String");

if (cls == 0) {
goto destroy;
}

jstr = env -> NewStringUTF("");

args = env-> NewObjectArray(0, cls, NULL);

Gordon Beaton

unread,
Aug 20, 2001, 8:44:08 AM8/20/01
to
On 20 Aug 2001 05:09:48 -0700, Luke Bertha wrote:
> I am quite surprised because even though the program executes printf
> it does not print out anything!

Some newlines might help this. Or use fprintf(stderr,"...") instead.

> I also searched strlen either in the jdk1.3 or in the gcc include
> directories but have not found. Where is it?

The function itself is in libc.so, but the call to it is probably in
libjvm.so.

I have just compiled and run your code without making any changes.
There are still some errors in it, but they are not related to the
segfault you are getting.

This is my platform:

uname -a:
SunOS piraat 5.8 Generic_108528-07 sun4u sparc SUNW,Ultra-5_10

java -version:
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

gcc --version:
2.95.3


This is how I built the program:

gcc -ggdb -Wall -I $JDK/include -I $JDK/include/solaris -c invoke.cxx -o invoke.o
gcc -o invoke invoke.o -L $JDK/jre/lib/sparc -ljvm -R $JDK/jre/lib/sparc

This is the output:

[piraat]$ ./invoke
Exception in thread "main" java.lang.NoSuchMethodError: main
Let's go!Start to create a JVM!JVM have just been created!
[piraat]$

( Don't worry that the exception is shown before the other output. It
occurs afterwards but appears first because stdout and stderr are
buffered differently. )

The small errors I mentioned are as follows, however none of them are
preventing you from starting the JVM:

- Unless you want the classpath to be exactly "USER_CLASSPATH" you
can't set the classpath this way:

options[0].optionString ="-Djava.class.path=USER_CLASSPATH";

If USER_CLASSPATH had been anything but a string literal, you would
have had to concatenate the strings using strcat() or similar method.
But since it is a string literal, you can do this:

options[0].optionString ="-Djava.class.path=" USER_CLASSPATH;

- you are still confusing the classes. You need to look up String for
the argument list, but you still need to look up HelloWorld in order
to run the java application. This is the reason for the
NoSuchMethodError I get in the example above.

- some newlines at the end of your printf statements would help
readability.

And one last thought that I have had the whole time... there is really
no C++ at all in your code, yet you insist on compiling it as though
it were and this strikes me as strange. I would prefer to change the
JNI calls to the C style, rename the source file something.c and
compile is as a C program instead.

Luke Bertha

unread,
Aug 21, 2001, 11:23:01 AM8/21/01
to
> This is how I built the program:
>
> gcc -ggdb -Wall -I $JDK/include -I $JDK/include/solaris -c invoke.cxx -o invoke.o
> gcc -o invoke invoke.o -L $JDK/jre/lib/sparc -ljvm -R $JDK/jre/lib/sparc
>
> This is the output:
>
> [piraat]$ ./invoke
I attempted to compile my code with the gcc commands you suggested and
I got some interesting staff:
Programs> ./hello

Start to create a JVM!
#
# HotSpot Virtual Machine Error, Internal Error
# Please report this error at
# http://java.sun.com/cgi-bin/bugreport.cgi
#
# Error ID: 5448524541442C4F43414C33544F524147450E435050002B FF
#
# Problematic Thread:
signal fault in critical section
signal number: 11, signal code: 1, fault address: 0x4, pc:
0xef662950, sp: 0xefffc860
ABORT: core dump
Segmentation Fault


> And one last thought that I have had the whole time... there is really
> no C++ at all in your code, yet you insist on compiling it as though
> it were and this strikes me as strange. I would prefer to change the
> JNI calls to the C style, rename the source file something.c and
> compile is as a C program instead.

You are right. The reason why I hanged on the C++ version is because I
would like to use this C++ code in the future. I will follow your
advice and change it to .c but first I would like to know for sure
that the root of the segfault is not a Sun bug.

Thanks,
Luke

Code:
include <jni.h>

#define PATH_SEPARATOR ';' /* define it to be ':' on Solaris */
#define USER_CLASSPATH "." /* where Prog.class is */

int main() {
printf("Let's go!");
JNIEnv *env=NULL;
JavaVM *jvm=NULL;
jint res ;
jclass cls;
jmethodID mid;
jstring jstr ;
jobjectArray args;

JavaVMInitArgs vm_args;
JavaVMOption options[1];

options[0].optionString ="-Djava.class.path="USER_CLASSPATH;

vm_args.version = 0x00010002;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = JNI_TRUE;
/* Create the Java VM */

fprintf(stderr, "Start to create a JVM!\n");
//res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
res = JNI_CreateJavaVM(&jvm,(void**)&env, &vm_args);
fprintf(stderr, "JVM have just been created!\n");


if (res < 0) {
fprintf(stderr, "Can't create Java VM\n");
exit(1);
}
//cls = env->FindClass( "HelloWorld");
cls = env->FindClass( "java/lang/String");
if (cls == 0) {
goto destroy;
}
jstr = env -> NewStringUTF("");

//args = env-> NewObjectArray(1, cls, jstr);

Gordon Beaton

unread,
Aug 21, 2001, 11:33:11 AM8/21/01
to
On 21 Aug 2001 08:23:01 -0700, Luke Bertha wrote:
> I attempted to compile my code with the gcc commands you suggested and
> I got some interesting staff:
> Programs> ./hello
> Start to create a JVM!
> #
> # HotSpot Virtual Machine Error, Internal Error
> # Please report this error at
> # http://java.sun.com/cgi-bin/bugreport.cgi
> #
> # Error ID: 5448524541442C4F43414C33544F524147450E435050002B FF
> #
> # Problematic Thread:
> signal fault in critical section
> signal number: 11, signal code: 1, fault address: 0x4, pc:
> 0xef662950, sp: 0xefffc860
> ABORT: core dump
> Segmentation Fault


Could it be the case that you are missing an important thread patch,
or one of the many other patches that Sun says is necessary in order
to run your particular JVM on your platform?

See:
http://java.sun.com/j2se/1.3/install-solaris-patches.html

Other than that, I have really no idea.

Luke Bertha

unread,
Aug 23, 2001, 2:20:44 AM8/23/01
to
> Could it be the case that you are missing an important thread patch,
> or one of the many other patches that Sun says is necessary in order
> to run your particular JVM on your platform?

It couldn't be because I installed all the recommended pathes last
month and I double checked it yesterday once more. I also have the
other security patches installed.
Can you post your version of source code in order to see what is
happening with it in my system?

Thanks,

Luke

Gordon Beaton

unread,
Aug 23, 2001, 2:47:24 AM8/23/01
to

I used *your* source code. It works for me.

Looking back at your original post in this thread, it seems you are
using jdk 1.3.1 on Solaris 2.5.1, but I can't see that your JDK is
supported on that Solaris version.

According to this:
http://java.sun.com/j2se/1.3/install-solaris.html

The Java 2 SDK, Standard Edition, v. 1.3.1 (J2SDK 1.3.1) is intended
for use on Solaris 2.6, Solaris 7, and Solaris 8 operating
environments.

Presumably this is the reason they don't list any required patches for
earlier Solaris versions either. Note that I was referring to the
patches required by the JDK, listed on the JDK page I mentioned
earlier, not other securtity patches or upgrades normally recommended
by Sun.

Perhaps try downloading one of the older JDKs that does support 2.5.1
and try your code with that, or try a newer version of Solaris if you
have access to such a machine.

Luke Bertha

unread,
Aug 23, 2001, 10:33:21 AM8/23/01
to
> Looking back at your original post in this thread, it seems you are
> using jdk 1.3.1 on Solaris 2.5.1, but I can't see that your JDK is
> supported on that Solaris version

I think this could be very much the case! I downloaded and installed
jdk1.2.2. I got some linking error but I'm optimistic:

>gcc -o hello hello.o -L/home/JDK/jre/lib/sparc -ljvm
-R/home/JDK/jre/lib/sparc
ld: fatal: library -ljvm not found
ld: fatal: File processing errors. No output written to hello.

I searched after -ljvm but not found.I have found though a libjvm.so
file in /jre/lib/sparc/classic which could be in some connection with
the missing -ljvm library. However by linking with -R to
/jre/lib/sparc/classic I got the same library -ljvm fatal error as
before. Where is -ljvm?

Gordon Beaton

unread,
Aug 23, 2001, 11:11:34 AM8/23/01
to
On 23 Aug 2001 07:33:21 -0700, Luke Bertha wrote:
> I think this could be very much the case! I downloaded and installed
> jdk1.2.2. I got some linking error but I'm optimistic:
>
> >gcc -o hello hello.o -L/home/JDK/jre/lib/sparc -ljvm
> -R/home/JDK/jre/lib/sparc
> ld: fatal: library -ljvm not found
> ld: fatal: File processing errors. No output written to hello.
>
> I searched after -ljvm but not found.I have found though a libjvm.so
> file in /jre/lib/sparc/classic which could be in some connection with
> the missing -ljvm library. However by linking with -R to
> /jre/lib/sparc/classic I got the same library -ljvm fatal error as
> before. Where is -ljvm?

-ljvm means link with libjvm.so (or libjvm.a), and it's there in
$JDK/jre/lib/sparc/classic. I built your code for 1.2.2, like this:

compile (all this on one line):


gcc -ggdb -Wall
-I $JDK/include
-I $JDK/include/solaris
-c invoke.cxx -o invoke.o

link:
gcc -o invoke invoke.o
-L $JDK/jre/lib/sparc/classic
-L $JDK/jre/lib/sparc/native_threads
-ljvm -lthread

To run the program I set LD_LIBRARY_PATH first (example is for bash):

export LD_LIBRARY_PATH=$JDK/jre/lib/sparc/classic:$JDK/jre/lib/sparc/native_threads
./invoke

The results are as before, no segmentation fault:

Exception in thread "main" java.lang.NoSuchMethodError: main
Let's go!Start to create a JVM!JVM have just been created!

(again, the exception actually occurs after the JVM has started and is
only because the code is looking for main in the wrong class)

Luke Bertha

unread,
Aug 24, 2001, 4:26:22 AM8/24/01
to
Here we go: HelloWorld works! I am able to invoke HelloWorld.java. I
tried the program out with several java prgrams and invoke.cxx can
only invoke java classes with plain text output. It is not able to
invoke classes with gui,awt etc.. I write in invoke.cxx

cls = env ->FindClass("GuiDemo");

GuiDemo.java imports javax.swing.* and java.awt.*
No matter which Java class with GUI I intend to invoke I get the same
run time error:
>./invoke
Let's go!


Start to create a JVM!

JVM have just been created!

Exception in thread "main" java.lang.UnsatisfiedLinkError:
/home/jessicat/jdk1.2.2/jre/lib/sparc/libawt.so: ld.so.1: ./hello:
fatal: libmlib_image.so: open failed: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java, Compiled
Code)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java, Compiled Code)
at java.lang.Runtime.loadLibrary0(Runtime.java, Compiled Code)
at java.lang.System.loadLibrary(System.java, Compiled Code)
at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java,
Compiled Code)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.loadLibraries(Toolkit.java, Compiled Code)
at java.awt.Toolkit.<clinit>(Toolkit.java:903)
at java.awt.Component.<clinit>(Component.java:257)


I compile and link the program with the same gcc commands you
suggested. I checked and libawt.so and libmlib_image.so is in
$JDK/jre/lib/sparc ld.so.1 is in /usr/lib.
I tried to attach /usr/lib first in LD_LIBRARY_PATH than used
-I/usr/lib during compilation and -L/usr/lib during linking. It didn't
work. What is missing?

Gordon Beaton

unread,
Aug 24, 2001, 4:56:05 AM8/24/01
to
On 24 Aug 2001 01:26:22 -0700, Luke Bertha wrote:
> Exception in thread "main" java.lang.UnsatisfiedLinkError:
> /home/jessicat/jdk1.2.2/jre/lib/sparc/libawt.so: ld.so.1: ./hello:
> fatal: libmlib_image.so: open failed: No such file or directory

The thing about dynamic linking is that there can be a long chain of
dependencies, and even though one file is found, if something it
depends on is missing, it can't load.

> I tried to attach /usr/lib first in LD_LIBRARY_PATH than used
> -I/usr/lib during compilation and -L/usr/lib during linking. It didn't
> work. What is missing?

/usr/lib/ is in the default library path, so you don't need to specify
it. Also -I only tells the compiler where to find header files
(#include <foo.h>), so really neither of these help when you try to
run the program.

If you go to the directory containing libawt.so and type:

ldd libawt.so

you get a list of libraries that libawt.so depends on. The ones whose
paths are listed are already found, so you don't need to worry about
them. If there are any that say "not found" then you need to add
something to LD_LIBRARY_PATH so that they can be found. Also ldd will
report "not found" for files that are in fact right there, if they in
turn have any "not found" entries.

If you look at the $JDK/jre/bin/java script you will see that it adds
the following three directories to LD_LIBRARY_PATH:

$JDK/jre/lib/${proc}/${ttype}
$JDK/jre/lib/${proc}/${vmtype}
$JDK/jre/lib/${proc}

where
proc is e.g. sparc
ttype is either native_threads or green_threads
vmtype is either classic or hotspot or server

(exactly which choices there are and which paths are added can vary
depending on which JDK version you have, so have a look at the java
script).

Try adjusting LD_LIBRARY_PATH then type "ldd libawt.so" again and see
that it finds all of the necessary libraries. Then you should be able
to run your program.

Luke Bertha

unread,
Aug 27, 2001, 4:42:09 AM8/27/01
to
(Gordon Beaton) wrote in message news:<9m54r5$q8q$1...@news.du.uab.ericsson.se>...

> Try adjusting LD_LIBRARY_PATH then type "ldd libawt.so" again and see
> that it finds all of the necessary libraries. Then you should be able
> to run your program.

I did and it works!! The trick was to specify the $JDK/jre/lib/sparc
in LD_LIBRARY_PATH because libawt.so is in this directory. It can
almost perfectly visualize the GUI windows. There is some font
difficulty left. I suppose it is in connection with unicode. When I
run the program:


> ./invoke
Let's go!
Start to create a JVM!
JVM have just been created!

Font specified in font.properties not found [-b&h-lucida
sans-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1]
Font specified in font.properties not found [-b&h-lucida sans
typewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1]
Font specified in font.properties not found [-b&h-lucida
bright-demibold-r-normal--*-%d-*-*-p-*-iso8859-1]
Font specified in font.properties not found [-b&h-lucida
bright-medium-r-normal--*-%d-*-*-p-*-iso8859-1]
Font specified in font.properties not found [-b&h-lucida sans
typewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1]
Font specified in font.properties not found [-b&h-lucida sans
typewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1]
Font specified in font.properties not found [-b&h-lucida
sans-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1]
Font specified in font.properties not found [-b&h-lucida sans
typewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1]
:
:
And finally it draws the GUI window.

I checked $JDK/jre/lib/font.properties and the font types mentioned
above are really not there. My first question:Do I have to download
some unicode patch? And second: if yes do I have to include
$JDK/jre/lib in my LD_LIBRARY_PATH?

Luke

0 new messages