Borrar filtros
Borrar filtros

Why are some of my functions 'Undefined' in my standalone executable compiled from MATLAB source and pcode files?

3 visualizaciones (últimos 30 días)
I have a MATLAB standalone app compiled from many different source code files. Some of the dependencies for this app are sensitive IP so I identified all required files using requiredFilesAndProducts and I obfuscated those sensitive dependencies (since source code is to be delivered as part of this project). Some of those dependencies use functions from other dependencies so I recursively called requiredFilesAndProducts to get a complete list of all required files. From that list, I then ran pcode against the sensitive IP and gathered all the pcode files into one location.
When I compile the standalone executable, I add the path to the pcode folder addpath(genpath('C:\path\to\pcode\folder')) as well as the safe to distribute MATLAB source code files and compile compiler.build.standaloneApplication('MATLAB_SOURCE_CODE_FILE_Y.m').
When I run the standalone app, some of the functions from the pcode will yield Undefined function 'Some_Function' for input arguments of type 'char'. Error in PCODE_FILE_X Error in MATLAB_SOURCE_CODE_FILE_Y (line 85) despite the fact that Some_Function has a corresponding pcode file in the pcode folder.
I tried listing at the bottom of the main function for the standalone app all the pcode files as other threads suggest but that doesn't solve the problem for pcode files referencing functions from other pcode files. Any ideas?
  3 comentarios
Paul
Paul el 19 de Abr. de 2024
>> addpath(genpath('C:\path\to\pcode\folder'));
>> rehash
>> addpath(genpath('C:\path\to\source\code'));
>> rehash
>> fList = matlab.codetools.requiredFilesAndProducts('MATLAB_SOURCE_CODE_FILE_Y.m');
>> any(~cellfun(@isempty, strfind(fList, 'Some_Function.p')))
ans =
logical
0
Bruno Luong
Bruno Luong el 19 de Abr. de 2024
Editada: Bruno Luong el 19 de Abr. de 2024
>> any(~cellfun(@isempty, strfind(fList, 'Some_Function.p')))
ans =
logical
0
So that means the compiler cannot see by parsing the code that Some_Function.p is needed.
It might be called by some odd way such as EVAL or FEVAL. You might add this file manually bu hand using "-a" option pf MCC command.
The list of files that are packaged are in fList, you can check what else is missing.
You might repeat -a if similar issue with other files.

Iniciar sesión para comentar.

Respuesta aceptada

Paul
Paul el 25 de Abr. de 2024
I found the solution! You need to manually include the .p files in the compiler options struct. It would be nice if the matlab compiler could automagically resolve these dependencies...
opts = compiler.build.standaloneApplicationOptions('MATLAB_SOURCE_CODE_FILE_Y.m');
fList = matlab.codetools.requiredFilesAndProducts('MATLAB_SOURCE_CODE_FILE_Y.m');
fList(1) = []; % remove first entry as it is the name of the file we are doing this against
for i=1:length(fList)
pcode(fList{i});
end
% delete all .m files that have .p equivalents
% create a list of the .p file paths
opts.AdditionalFiles = pcodeList; % This should be all the .p code files
compiler.build.standaloneApplication(opts);

Más respuestas (1)

Walter Roberson
Walter Roberson el 25 de Abr. de 2024
Use the "-j" switch to the MATLAB Compiler to automatically convert all M files to P-code (in R2022b or later)
The "-s" option of the MATLAB Compiler doesn't obfuscate the M code, it obfuscates the file and folder structure inside the package and also supports encryption of data files.
It seems to me that adding those switches would be a lot easier than what you are currently doing.

Categorías

Más información sobre Programming Utilities en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by