JAVA Unsatisfied Link Error
- From: Matthew <mattcbro@xxxxxxxxxxxxx>
- Date: Tue, 14 Feb 2006 17:41:43 -0500
I've been getting rather frustrated with the native interface to JAVA
within Matlab. I wish to load some Java classes that use the JNI
interface to call some C code. I installed SWIG for this purpose and
decided to test it in Matlab. In particular I compiled in the Swig
example folder the simple example. It runs just fine as a standalone
java program. However it fails miserably when trying to run it under
Matlab.
First, because it is not really possible in Matlab 6.5 to load
unpackaged classes (yes I've tried declaring them public to no avail)
I had to modify the Swig code. I am running this under windows XP 64.
My directory structure is set up as follows:
classpath.txt is in D:\Apps\Matlab6p5\work and contains the path to
my test directory
D:\Projects\JavaSrc
My class files are in
D:\Projects\JavaSrc\tutorials
A copy of the C dll can be found in the tutorials directory, the
JavaSrch directory, the Matlab work directory and in C:\Windows,
which is in my PATH environment.
The source for the main class examplemain.java is
package tutorials ;
public class examplemain {
static {
try {
String libraryPath = System.getProperty("java.library.path",".");
System.out.println ("library path = " + libraryPath + "\n");
System.loadLibrary("./example");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. See the
chapter on Dynamic Linking Problems in the SWIG Java documentation
for help.\n" + e);
// System.exit(1);
}
}
public static void run(String argv[]) {
// Call our gcd() function
int x = 42;
int y = 105;
int g = example.gcd(x,y);
System.out.println("The gcd of " + x + " and " + y + " is " + g);
// Manipulate the Foo global variable
// Output its current value
System.out.println("Foo = " + example.getFoo());
// Change its value
example.setFoo(3.1415926);
// See if the change took effect
System.out.println("Foo = " + example.getFoo());
}
}
The example and exampleJNI classes are unchanged from the SWIG
sources.
Here's what happens:
import tutorials.*
ex = examplemain ;
library path =
D:\Apps\Matlab6p5\bin\win32;.;C:\WINDOWS\system32;C:\WINDOWS;D:\Apps\M
atlab6p5\bin\win32;D:\Apps\Tcl\bin;d:\apps\imagemagick-6.2.5-q16;d:\ap
ps\graphicsmagick-1.1.7-q8;D:\Apps\Perl\bin\;D:\Apps\ruby\bin;D:\Apps\
texmf\miktex\bin;C:\Apps\watcom-1.3\binnt;C:\Apps\watcom-1.3\binw;C:\W
INDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;d:\apps\matlab6p5\
bin\win32;C:\Program Files (x86)\Common Files\GTK\2.0\bin;C:\Program
Files (x86)\QuickTime\QTSystem\;D:\Apps\Objective Caml\bin;
(Note that examplemain loads without complaint)
ex.run('run') ;
??? Java exception occurred:
java.lang.UnsatisfiedLinkError: gcd
at tutorials.exampleJNI.gcd(Native Method)
at tutorials.example.gcd(example.java:12)
at tutorials.examplemain.run(examplemain.java:22)
Unfortunately java can not find the symbol links that it has no
problem finding outside of the Matlab environment.
I even went back and included a .def file to guarantee that the
symbols were declared inside the example.dll file during my original
compiling and linking of the C code.
I'm at wits end on how to make this work. Is there an issue with
using Java code that uses the Java foreign language interface in
Matlab?
.
- Prev by Date: Re: HELP MEE
- Next by Date: Possible to use matrices instead of the dreaded FOR loop?
- Previous by thread: Optimization with fmincon...Help!
- Next by thread: Possible to use matrices instead of the dreaded FOR loop?
- Index(es):
Relevant Pages
|