Need help creating a DLL from an M file and accessing its functions from Java

Started by aebeytin February 1, 2008
Hi all,

I am attempting to convert a .M script (or function, preferably) to a
DLL that I can then access via a Java program. I'm currently using
version 7.1, though my solution needs to work with later versions as
well. Here's what I have at the moment:

File test.m:
function [ data ] = test()
data = 7;

Compiled in MATLAB with the command:
mcc -W lib:test -T link:lib test

Java access function (uses JNative):
try {
JNative testFunc = new JNative(dllLoc, "test");
// set return value type, invoke, print result, and clean up
} catch (NativeException e) {
System.err.println("NativeException accessing DLL.");
} catch (IllegalAccessException e) { // Print exception info }
The first instruction fails, throws a NativeException, and I get this
NativeException accessing DLL.
Function test not found

It seems that there is no function "test" specifically in the DLL.
How do I compile this DLL so that I can access it in this way, and/or
what do I need to do about the name of the function? Do I need to use
a different method completely?