开发者

unable to load a DLL in MATLAB through Java

I am working on a Java GUI application that uses MATLAB code for calculations. However, the MATLAB code itself uses a DLL file. I packed all my MATLAB functions into a class and created a jar file.

I added the C header file and DLL file in the project root folder of the Java project and added the jar containing MATLAB code to properties. However, when I call the methods, it seems to execute, but its unable to load the DLL file.

Here is the error message I get:

{??? Error using ==> loadlibrary at 477
There was an error loading the library
**"C:\Users\AUG\Documents\Backup\SourceTracing\epanet2.dll"**
FAiled..Error using ==> loadlibrary at 477
Undefined function or variable 'epanet2_proto'.

There was an error loading the library
"C:\Users\AUG\Documents\Backup\SourceTracing\epanet2.dll"
Error in ==> epanetloadfile at 31

Undefined function or variable 'epanet2_proto'.

Error in ==> sourceTraceGUI at 8

when I actually checked the address, the DLL file is there along with the header file as well in that directory.

Update

I tried all of Richie's suggestions.

  1. I could run the method that uses DLL on MATLAB.

  2. I could call any normal method from Java that doesn't use the DLL.

  3. I 开发者_运维技巧could even call the method that uses the DLL, but the problem is occurring when the library is supposed to load.

It says

Error using ==> loadlibrary at 477
There was an error loading the library
"C:\Users\AUG\Documents\Backup\SourceTracing\epanet2.dll"

If I run the code in MATLAB though, it all works fine. It is just when I run from Java, the DLL doesn't load.


I posted this question in the Matlab forum and finally got some answers. For those who have the same problem in future, refer to this link.

http://www.mathworks.com/matlabcentral/answers/11321-loading-a-dll-in-mathlab-through-java


There are lots of places where the problem could be, and your example isn't reproducible, so its difficult to answer as it is. In order to get to the bottom of this, we need to unpick the problem, and narrow down the source of the error. Here are some things to try.

Can you run your MATLAB modelling code directly, including running the calls to the DLL?

Does your MATLAB code run if you don't call the DLL? (Maybe fake the call, and just have it return a number for now.)

Can you call other methods form the DLL, form within your JAVA project?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜