Why am I unable to compile a code that contains the SYSTEM command using the MATLAB Compiler?

2 views (last 30 days)
Why am I unable to compile a code that contains the SYSTEM command using the MATLAB Compiler?
When I try to compile a simple code like the following:
function test
system('ls')
I get the following error message:
Warning: No M-function source available for "system", assuming
function [varargout] = system(varargin)
NOTE: This will produce a link error in stand-alone code
unless you provide a hand-written definition for this function.
Setting MSVCDir for use with MSVC 6.0
test.obj : error LNK2001: unresolved external symbol _mlfNSystem
compiled\test.exe : fatal error LNK1120: 1 unresolved externals
MBUILD.BAT: Error: Link of 'compiled\test.exe' failed.
??? Error using ==> mbuild
Unable to complete successfully
??? Error: An error occurred while shelling out to mbuild (error code = 1).
Unable to build executable (specify the -v option for more information).
Error in ==> D:\MATLAB6p5\toolbox\compiler\mcc.dll

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 22 Jan 2010
This feature has been added in MATLAB Compiler 4.0 (R14). If you are using a previous version, read the following:
Using MATLAB Compiler 3.x (R13), you cannot compile an MATLAB code that make a call to the SYSTEM function. This has been forwarded to our development staff for consideration for a future release of MATLAB.
To work around this issue, you have several options:
1) Use the Bang (!) operator
OR
2) Use the DOS or UNIX command as follows:
if ispc
dos('dir')
else
unix('ls')
end

More Answers (0)

Categories

Find more on C Shared Library Integration in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!