Loading a DLL in MATLAB through JAVA

3 ビュー (過去 30 日間)
Nick B
Nick B 2011 年 7 月 11 日
Hi,
I have a running application in Mathlab, that also uses some C DLL files.
I have created a JAVA package using the JA builder of mathlab functions. Then I put the DLLs in the JAVA main project folder.
I could invoke any method that doesnt use the DLL and it works fine. But whenever I invoke a method that uses the DLL files, it crashes and here is the stacktrace.
{??? Error using ==> loadlibrary at 477 FAiled..Error using ==> loadlibrary at 477 There was an error loading the library There was an error loading the library "C:\Users\AUG\Documents\Backup\SourceTracing\epanet2.dll" "C:\Users\AUG\Documents\Backup\SourceTracing\epanet2.dll" Undefined function or variable 'epanet2_proto'. Undefined function or variable 'epanet2_proto'.
Error in ==> epanetloadfile at 31
Caused by: Error using ==> feval Undefined function or variable 'epanet2_proto'. } ... Matlab M-code Stack Trace ... file C:\Program Files\MATLAB\R2010b\toolbox\compiler\mcr\matlab\general\loadlibrary.m, name loadlibrary, line 477. file C:\Users\AUG\AppData\Local\Temp\AUG\mcrCache7.14\Source12\SourceTrace\epanetloadfile.m, name epanetloadfile, line 31. com.mathworks.toolbox.javabuilder.MWException: Error using ==> loadlibrary at 477 There was an error loading the library "C:\Users\AUG\Documents\Backup\SourceTracing\epanet2.dll" Undefined function or variable 'epanet2_proto'. at com.mathworks.toolbox.javabuilder.internal.MWMCR.mclFeval(Native Method) at com.mathworks.toolbox.javabuilder.internal.MWMCR.access$600(MWMCR.java:23) at com.mathworks.toolbox.javabuilder.internal.MWMCR$6.mclFeval(MWMCR.java:902) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.mathworks.toolbox.javabuilder.internal.MWMCR$5.invoke(MWMCR.java:800) at $Proxy0.mclFeval(Unknown Source) at com.mathworks.toolbox.javabuilder.internal.MWMCR.invoke(MWMCR.java:475) at SourceTrace.SourceTrace.epanetloadfile(SourceTrace.java:580) at leakdetection.water.source.tracing.Test.<init>(Test.java:46) at leakdetection.water.source.tracing.Test.main(Test.java:19) BUILD SUCCESSFUL (total time: 13 seconds)

採用された回答

Friedrich
Friedrich 2011 年 7 月 11 日
Hi,
When compiling code which uses loadlibrary you have to take care of some things first:
If you need to distribute your shared library to other users who will use it in MATLAB themselves or who will use your MATLAB functions which call the library; they would also need a compiler to create a thunkfile, unless you create one for them and work with a prototype M-file:
1. Use the 'mfilename' option of LOADLIBRARY, this will generate a prototype M-file and the thunkfile:
loadlibary('myLibrary','myLibrary.h','mfilename','myLibrary.m')
2. In the code which uses the library, instead of using the header:
loadlibrary('myLibrary','myLibrary.h')
Now use the prototype M-file:
loadlibrary('myLibrary',@myLibrary)
If your end-users call the library by themselves you may need to tell them this.
3. Distribute the actual library (myLibrary.dll), the prototype M-file (myLibrary.m) and the thunkfile (myLibrary_thunk_pcwin64.dll) to your end-users.
  1 件のコメント
Nick B
Nick B 2011 年 7 月 11 日
Thanks! I will try.

サインインしてコメントする。

その他の回答 (1 件)

Kaustubha Govind
Kaustubha Govind 2011 年 7 月 11 日
As the error suggests:
Undefined function or variable 'epanet2_proto'
You need to add the prototype file epanet2_proto.m to the archive (add it under "Additional Files" if using DEPLOYTOOL or append using -a option if using MCC).

カテゴリ

Help Center および File ExchangeJava Package Integration についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by