Solved

java.lang.UnsatisfiedLinkError:  (A file or directory in the path name does not exist)

Posted on 2014-02-27
13
1,843 Views
Last Modified: 2014-03-09
Tried a few examples on AIX box and everytime I get the error as below:-

Calling C code from Java using JNI

java HelloWorld
The java class could not be loaded. java.lang.UnsatisfiedLinkError: ctest (Not found in java.library.path)

Open in new window


The "libctest.so" is very much in the path and LD_LIBRARY_PATH.

On running below  command.
export LD_LIBRARY_PATH=.
I get.
>  java HelloWorld
The java class could not be loaded. java.lang.UnsatisfiedLinkError: ctest (A file or directory in the path name does not exist.)

Open in new window



Below tutorial gives similar issue
Calling C From Java Is Easy

I am not sure what is going wrong
0
Comment
Question by:jgdvishnu
  • 7
  • 6
13 Comments
 

Author Comment

by:jgdvishnu
ID: 39893823
The error is "A file or directory in the path name does not exist".

I am putting the *.so in the path and LD_LIBRARY_PATH.
Is there anything else that i need to put on the path for this java file to run?
0
 
LVL 4

Assisted Solution

by:popesy
popesy earned 200 total points
ID: 39894436
Hi

Have you set up your java CLASSPATH environment variable?

If not, check that and try again.

# print $CLASSPATH

Open in new window


Should give you the path to the JDK/Java libs.

Cheers, JP.
0
 

Author Comment

by:jgdvishnu
ID: 39894639
I tried that out but still get the same error

training-> export CLASSPATH=.:/usr/java5_64/jre/bin:/usr/java5_64/bin:/usr/java5_64/include

training-> print $CLASSPATH
.:/usr/java5_64/jre/bin:/usr/java5_64/bin:/usr/java5_64/include

training-> java HelloWorld
The java class could not be loaded. java.lang.UnsatisfiedLinkError: ctest (A file or directory in the path name does not exist.)

training-> ls
HelloWorld.class  HelloWorld.java   libctest.so
HelloWorld.h      ctest.c

Open in new window

0
 
LVL 4

Expert Comment

by:popesy
ID: 39894665
Sorry.  Are you saying that you have got $CLASSPATH set?

Also,  are you sure that there is no typo in the path?

Cheers, JP.
0
 
LVL 4

Expert Comment

by:popesy
ID: 39894706
Ok,

You could try;

# ldd libctest.so

Open in new window


to evaluate library dependencies.

Also try;

# truss java HelloWorld

Open in new window


And see whether you have any 'load' system calls that look like they have failed in the output.

Cheers, JP.
0
 

Author Comment

by:jgdvishnu
ID: 39894776
I checked there is no typo. Also I cross verify the commands, what they do.

The ldd(library dependencies) show
training-> ldd libctest.so
libctest.so needs:
         /usr/lib/libc.a(shr.o)
         /unix
         /usr/lib/libcrypt.a(shr.o)

Open in new window



However on running truss I do see "Err#25 ENOTTY" not sure what it means.

Still it is not clear to me "what directory or path does not exist and where".
error-from-Truss-command.txt
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 4

Expert Comment

by:popesy
ID: 39895187
The truss output doesn't show any obvious gotchas.  I think the errnotty is not a problem here.

Is the 'HelloWorld' code your own?  Perhaps there is something in your code that is making an incorrect system call to your ctest library.

Cheers, JP.
0
 

Author Comment

by:jgdvishnu
ID: 39895227
The Example that I tried is:-

Calling C code from Java using JNI - URL :-
http://stuf.ro/calling-c-code-from-java-using-jni

Code is attached.


//Command to execute is:-
java -Djava.library.path=.:/usr/java5_64/jre/bin:/usr/java5_64/bin:/usr/java5_64/include HelloWorld

//Output is :-
The java class could not be loaded. java.lang.UnsatisfiedLinkError: ctest (A file or directory in the path name does not exist.)

// the Java Version that was used
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build pap64devifx-20110627 (SR12 FP5 ))
IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 AIX ppc64-64 j9vmap6423ifx-20110624 (JIT enabled)
J9VM - 20110623_85457_BHdSMr
JIT  - 20100623_16197ifx10_r8
GC   - FP22011_06)
JCL  - 20110627

Open in new window


I verified path "/usr/java5_64/include" contains jni.h.
However what makes me think is, "if there is some other command for Java 5 ?"
HelloWorld.h
ctest.c
HelloWorld.java
0
 
LVL 4

Assisted Solution

by:popesy
popesy earned 200 total points
ID: 39899845
Hello

I'm sorry to say that it's getting a little out of my knowledge now.

Perhaps you could try explicitly defining the path to the libctest.so using the

-Djava.library.path

Open in new window


so assuming your working dir is /tmp/java/myspace

java -Djava.library.path=/tmp/java/myspace HelloWorld

Open in new window


(This also assumes that the libctest.so is in this library path)

See how you go.

Cheers, JP.
0
 

Accepted Solution

by:
jgdvishnu earned 0 total points
ID: 39905669
it was not any of the path issue listed. it was adding -maix64 in command line of "gc" so that the so file is made for the 64 bit machine and not 32 bit.
The command was -

gcc -o libctest.so   -shared -maix64 -I/usr/java5/include com.insight.CTest.c -lc

Open in new window

0
 
LVL 4

Expert Comment

by:popesy
ID: 39905686
Glad you got it figured out in the end.

Cheers, JP.
0
 

Author Comment

by:jgdvishnu
ID: 39913685
i want to resend as my solution is the only solution and not others.
0
 

Author Closing Comment

by:jgdvishnu
ID: 39915657
Not knowing about -maix64 option in command like took a lot of my time
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now