www.gusucode.com > rtwdemos 工具箱matlab源码程序 > rtwdemos/shrlib_demo/run_rtwdemo_shrlib_app.m
% File: run_rtwdemo_shrlib_app.m % Abstract: % Script to compile/link/execute example files for rtwdemo_shrlib.mdl % % Usage: % It is recommended to create a new directory before running this % script. % % Note: % If the model name or application name is modified, be sure to change % them in this file accordingly to have a successful build. % % Requirements: % Requires lcc on Win32 platform; requires VC8.0 professional edition % on Win64 platform; requires cc on Sol64 platform; requires gcc on other % Unix based platforms. % % Copyright 2006-2014 The MathWorks, Inc. % disp(' '); disp(DAStudio.message('RTW:ert:ShrLibDemo')); model = 'rtwdemo_shrlib'; appName = 'rtwdemo_shrlib_app'; appH = [appName '.h']; appC = [appName '.c']; if(~exist(fullfile('.',appH), 'file')||~exist(fullfile('.',appC), 'file')) disp(' '); disp(DAStudio.message('RTW:ert:ShrLibAppFilesNotFound')); disp(DAStudio.message('RTW:ert:ShrLibCopyingInstallDir')); copyfile(fullfile((matlabroot), 'toolbox', 'rtw', 'rtwdemos', 'shrlib_demo',appH)); copyfile(fullfile((matlabroot), 'toolbox', 'rtw', 'rtwdemos', 'shrlib_demo',appC)); disp(DAStudio.message('RTW:ert:ShrLibCopyingInstallDirDone')); end cmdExec = ['.' filesep appName]; load_system(model); disp(' '); disp(DAStudio.message('RTW:ert:ShrLibParameterList')); disp(' '); disp(['LIMIT: ' num2str(LIMIT) '; INC: ' num2str(INC) '; RESET: ' ... num2str(RESET) '; K: ' num2str(K)]); open_system(model); set_param(model, 'TemplateMakefile', 'ert_default_tmf'); switch ert_default_tmf case 'ert_lcc.tmf' def_underscore = '-DLCCDLL '; case 'ert_bc.tmf' def_underscore = '-DBORLANDCDLL '; otherwise def_underscore = ''; end if ~isempty(def_underscore) disp(' '); disp(DAStudio.message('RTW:ert:ShrLibAttn')); end % load model and rebuild the target. disp(' '); disp(DAStudio.message('RTW:ert:ShrLibBuild', model)); disp(' '); rtwbuild(model); % use the mex API to create an engine application incPath = [ model '_ert_shrlib_rtw ']; cmd = ['mex -client engine -I' incPath ' ' appC]; eval(cmd); % To incorporate the shared library in a larger project, custom compile and % link commands may need to be created. The following commented lines gives % an example of how to create and execute these commands in MATLAB. % % cmdComp = ['gcc -c -I./' model '_ert_shrlib_rtw ' appC]; % cmdLink = ['gcc -o ' appName ' ' appName '.o -ldl']; % system(cmdComp); % system(cmdLink); if (isunix && ~exist(['./' appName], 'file')) || ... (ispc && ~exist([appName '.exe'], 'file')) DAStudio.error('RTW:ert:ShrLibNoExeFound'); else % run the application executable disp(' '); disp(DAStudio.message('RTW:ert:ShrLibExecute')); disp(' '); system(cmdExec); end disp(' '); disp(DAStudio.message('RTW:ert:ShrLibEnd')); disp(' '); % [EOF]