How can I create an executable file from function that need to "addpath" some folders and call one hundred functions and dll files?

Hi all. I'm using a code that that need to setpath some foders and run properly in matlab, I create an executable file by mcc- m write_dfsu_2D.m, but when I open .exe file, it doesn't work. for more, there is an "if cluase" that isn't true when I run function, but is true when I run executable file and make an error:
if (exist(MatlabDMdll,'file') == 2)
elseif (exist(MatlabDMdllDev,'file') == 2)
debug = true;
MatlabDMdll = MatlabDMdllDev;
else
error(id('LibNotFoundDLL'),'Can not find dfsManager library dll (MatlabDM.dll)')
end
when the black window of executable file is opened, I face this probles:
??? Error using ==> dfsManager.dfsManager at 147
can not find the dfsManager library dll matlabDM.dll
Error in ==> write_dfsu_2D at 8
dfsManager:dfsManager:LibNotFoundDLL
I'm beginner and I have to use some examples of http://www.mikebydhi.com/Download/DocumentsAndTools/Tools/MATLABDFS2008.aspx but I don't know how can I create an executable file from this function. Could someone help me out please? Thanks in advance.

 Respuesta aceptada

Friedrich
Friedrich el 10 de Mayo de 2013
Editada: Friedrich el 10 de Mayo de 2013
Hi,
start here:
and VERY important in the case you use laodlibrary:
You need to add the DLL, (in 64bit also the generated thunk library) as shared ressource and helper file (-a flag for the mcc call).
You don't need to worry about paths and folders. All folder you add to your exe are added to the MATLAB search path at startup of your exe. So no addpath or CD is needed.

7 comentarios

Hi Friedrich, I'm very grateful to you for your help. Could you possibly help me more? As I read in the link that you recommended, I should attach the dll file before the compilation, but whatabout the functions that is called in the main function? I should mention the functions that exist in matlabroot? Somebody said that at first I should find the functions that is used in the code by depfun(mainfile.m). Is it necessary for me to do it?
and how about input files? I have to use
open('text.txt')
in this function and I don't know how can I introduce it to the executable file? I haven't ever heard anything about ctfroot, I should create it or it is exactly the directory that the dll files and subfunctions exist in?
I've searched for a week but I coudn't succed. Is there any useful link that explain more detail about deployment basically?
Thousands of thanks.
You don't need to find the functions needed with depfun. MATLAB will do this for you during compilation and gather all files. Maybe use the deploytool (enter "deploytool" in the command line) for compilation. As main file use the file your currently use. As shared ressource and helper file add the DLL. Don't forget to adjust your code from
loadlibrary('DLL_name.DLL','HEADER.h')
to
loadlibrary('DLL_name.DLL',@prototype_mfile.m);
like mentioned in the link above.
The CTFROOT is created automatically when you start the compiled exe. So you don't need to worry about that one.
For inputfile you like to ship with your exe you would also need to add the text.txt as shared ressource and helper file so that file is available on the deployment machine.
Thanks alot,
They used this form of loadlibrary, and I have one additional mfile that called dfsmantest.m in it's library folder and loadlibrary(MatlabDMdll,@dfsManTest,'alias','DFSManLib') in code but when I try to create an executable file by using deploytool-and attaching matlabDM.dll and dfsmantest.m in "Add files/directories"- I face this error:
The file 'E:\MS\Lessons\thesis\Matlab\mbin\@dfsManager\lib\MatLabDM.dll' appears to be a MEX-file. It shadows the M-file 'E:\MS\Lessons\thesis\Matlab\mbin\@dfsManager\lib\MatLabDM.m' but will not execute properly at runtime, as it does not export a function named 'mexFunction.'
I can't find any .mex32 file in this folder, I should create one .mex32 file? Do you know what's the reason of this error?
Back in the older days the mex files had a .DLL extension and MATLAB interpreted a .DLL file as MEX file and MEX files have a higher priority than m file which will lead to the error your have. Simply rename the DLL and adjust the name in your loadlibrary call and you should be fine.
Zahura
Zahura el 20 de Mayo de 2013
Editada: Zahura el 20 de Mayo de 2013
I appreciate your consideration and your time,
It was great and this worked for me, thank you so much!
but another problem was appeared and I hope you help me to overcome this.
In this code they used several "calllib" commands that work fine when I'm using matlab function, but doesn't work when I'm using executable file. I read in this link:
"It is not possible to call a function in a MATLAB compiled dll using calllib. This is because a dll dependent on the mcr can not be loaded into MATLAB."
It means that I can't use calllib in executable file? If yes, is there any command that can be used instead of calllib?
I think this problem is because of the input file.
another problem that I have, is that is mentioned here:
but nobody has answered this, yet. Is it impossible to update the input file for executable file in each run?
I need to convert this code to .exe or .bat, and I lost one month on it, but I couldn't solve it . Is it impossible in matlab? Is there anyway to convert this code?
Thousands of thanks for your assistance
HI,
this part
"It is not possible to call a function in a MATLAB compiled dll using calllib. This is because a dll dependent on the mcr can not be loaded into MATLAB."
Means you can't use a MATLAB Compiler generated DLL back in MATLAB with loadlibrary and calllib.
However you don't have a MATLAB Compier generated DLL. So callib and loadlibray should work. So what does not work mean in detail? What error do you get when running which line of code?
In the case you wan't an alterated input file do NOT embed it into the CTF. At startup the MCR checks if the extracted CTF content changed, if so it reextracts the CTF which leads to overwriting the file and you get back the initial values. Its better to place an input file next to the exe and determine at runtime the path to it:
This will give the desired result.
That works fine, I so greatly appreciate, I will forever be beholden to you, I'd like to say thank you, For your helpful giving ways, I won't forget your kindness...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre C Shared Library Integration en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 10 de Mayo de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by