필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
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
Paul
Paul 2024년 4월 19일
>> 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 2024년 4월 19일
편집: Bruno Luong 2024년 4월 19일
>> 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.

댓글을 달려면 로그인하십시오.

채택된 답변

Paul
Paul 2024년 4월 25일
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);

추가 답변 (1개)

Walter Roberson
Walter Roberson 2024년 4월 25일
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.

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by