JAVA Unsatisfied Link Error



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?
.



Relevant Pages

  • Re: add a uicontainer or uipanel to a JPanel
    ... An axis is ultimately what I wanted to add to to a ... The uicontainers and uipanels and axes, for that matter, ... As for putting an axes in a Java container, ... Java enables richer GUI than Matlab ...
    (comp.soft-sys.matlab)
  • Re: add a uicontainer or uipanel to a JPanel
    ... An axis is ultimately what I wanted to add to to a ... The uicontainers and uipanels and axes, for that matter, ... As for putting an axes in a Java container, ... Java enables richer GUI than Matlab ...
    (comp.soft-sys.matlab)
  • Re: text rendering changes after last mac os x java update
    ... The MathWorks is still evaluating the Java for Mac OS X 10.5 Update 2 update released yesterday via Software Update. ... We have confirmed the issues described here on comp.soft-sys.matlab affecting MATLAB regarding Editor document tab appearance, and the Command Window/Editor font size. ... We are confident, however, that this Java update does improve reliability and resolves other issues impacting MATLAB users. ... The Command Window and Editor font size issue is still under investigation, and we are working with Apple to try to resolve this in another java update or patch. ...
    (comp.soft-sys.matlab)
  • Re: Adding a listener java/MATLAB interface
    ... I have a client/server program where the client calls java server code running in MATLAB. ... The Server receives an XML filename from the remote client and sends the file name on to a function in MATLAB, the function returns another filename which contains the results of the simulation. ...
    (comp.soft-sys.matlab)
  • Re: Adding a listener java/MATLAB interface
    ... I have a client/server program where the client calls java server code running in MATLAB. ... The Server receives an XML filename from the remote client and sends the file name on to a function in MATLAB, the function returns another filename which contains the results of the simulation. ...
    (comp.soft-sys.matlab)