最常用的就是可以查到再控制栏deploytool选择library complier打包,但是有问题就是比如果用了外部的求解器比如yalmip或者cplex的话用这个方法会找不到外部的求解器,网上找了很多,基本都大同小异。
后面分享一个亲测有效的打包方法,直接在控制栏输入
mcc -W 'java:myJavaPackage,PSO_SOCP' -T link:lib -d 'D:\matlab_output' -v 'D:\matlabwork\**.m' 'D:\matlabwork\*.m' -a 'D:\matlab\toolbox\YALMIP-master' -a 'D:\cplex\cplex\matlab'
'D:\matlab_output' 输出目录
'D:\matlabwork**.m' 'D:\matlabwork*.m'打包的包
'D:\matlab\toolbox\YALMIP-master' -a 'D:\cplex\cplex\matlab'外部依赖
详情可以参考这个
https://ww2.mathworks.cn/help/compiler/mcc.html#buth_o8
补充说明可能遇到的两个报错
错误使用 matlab.depfun.internal.cacheMtree (line 29)
MATLAB 代码 'D:\cplex\cplex\matlab\x64_win64\cplexoptimget.m' 包含以下语法错误:
L 22 (C 1): SYNER: 在 '.' 处出现解析错误: 使用的 MATLAB 语法可能无效。
出错 isClassdef>hasClassDef (line 37)
mt = matlab.depfun.internal.cacheMtree(file);
出错 isClassdef (line 21)
tf = hasClassDef(file);
出错 className_impl (line 118)
elseif isfullpath(whichResult) && isClassdef(whichResult)
出错 className (line 64)
[clsName, clsFile] = className_impl(whichResult);
出错 matlab.depfun.internal.MatlabSymbol/determineClassType (line 722)
[name, clsFile] = className(symObj.WhichResult, symObj.Symbol);
这个是因为我不知道什么时候动了这个文件夹的代码,多了个',',代开这个文件去掉就行
错误2
The file
'D:\matlab\toolbox\YALMIP-master\modules\dummy.m'
is empty (zero bytes long).
This file cannot be added to the CTF archive because it will cause an error
when the application or library is run. Add valid content to this file if
your application or library requires this file.
Failed to build CTF file: 'D:\matlab_output\myJavaPackage.ctf'.
Call to mcc failed with return code 1 (0x1).
这个是因为这个文件是dummy.m 是 YALMIP 工具箱中的一个文件,通常用于占位或其他辅助功能。
function dummy()
% Dummy function to satisfy MATLAB Compiler
disp('This is a placeholder function.');
end
打开这个文件往里面加一行这个就行