Relocate Code Generated from MATLAB Code to Another Development Environment
Once you generate code from your MATLAB® algorithm, you can relocate the code to another development environment,
such as a system or an integrated development environment (IDE) that does not include
MATLAB. You can package the files into a compressed file using the
packNGo
function at the command line or the
Package option in the MATLAB
Coder™ app. Once you create the zip file, you can relocate and unpack the
compressed zip file using a standard zip utility.
Package the Code
This example shows how to package the executable generated from the Generate C Code from MATLAB Code example using the
packNGo
function. You can also generate and package a
static library file or a dynamic library file. You cannot package a C-MEX file since
a MEX file requires MATLAB to run. For more information on packNGo
, see
packNGo
in RTW.BuildInfo Methods (MATLAB Coder).
The files needed to generate the executable are
reconstructSignalTestbench.m
,
GenerateSignalWithHighEnergyFFTCoeffs.m
, and the
reconstructSignalTestbench_Main.c
files from the Generate C Code from MATLAB Code example. Copy all these files into the
current working folder. To generate the executable, run the following commands in
the MATLAB command prompt:
cfg = coder.config('exe'); cfg.CustomSource = 'reconstructSignalTestbench_Main.c'; cfg.CustomInclude = ['"',pwd,'"']; codegen -config cfg -report reconstructSignalTestbench
If you are using Windows, you can see that
reconstructSignalTestbench.exe
is generated in the current
folder. If you are using a Linux machine, the generated executable is
reconstructSignalTestbench
. The
codegen
function generates the dependency source code and
the buildinfo.mat
file in the
codegen\exe\reconstructSignalTestbench
folder.
Load the buildInfo
object.
load('codegen\exe\reconstructSignalTestbench\buildinfo.mat')
Package the code in a .zip
file using the
packNGo
function.
packNGo(buildInfo,'fileName','reconstructSignalWithHighEnergyFFTCoeffs.zip');
The packNGo
function creates a zip file,
reconstructSignalWithHighEnergyFFTCoeffs.zip
in the current
working folder. In this example, you specify only the file name. Optionally, you can
specify additional packaging options. See Specify packNGo Options (MATLAB Coder).
This .zip
file contains the C code, header files,
.dll
files, and the executable that needs to run on the
external environment. Relocate the .zip
file to the destination
development environment and unpack the file to run the executable.
Prebuilt Dynamic Library Files (.dll)
If you compare the contents of the
codegen\exe\reconstructSignalTestbench
folder and the
reconstructSignalWithHighEnergyFFTCoeffs.zip
folder, you
can see that there are additional .dll
files that appear in the
zip folder. These .dll
files are prebuilt dynamic library files
that are shipped with MATLAB. Executables generated from certain System objects require these
prebuilt .dll
files. The Generate C Code from MATLAB Code example uses dsp.FFT
and dsp.IFFT
System objects whose
'FFTImplementation'
is set to 'FFTW'
. In
the FFTW mode, the executables generated from these objects depend on the prebuilt
.dll
files. To package code that runs on an environment with
no MATLAB installed, MATLAB
Coder packages these .dll
files in the zip folder. For a
list of all the System objects in DSP System Toolbox™ that require prebuilt .dll
files, see How To Run a Generated Executable Outside MATLAB.
To identify the prebuilt .dll
files your executable requires,
run the following command in the MATLAB command prompt.
files = getNonBuildFiles(buildInfo,'true','true');
For more details, see getNonBuildFiles
in Build Process Customization (MATLAB Coder).
For an example showing the Package option workflow to relocate code using the MATLAB Coder app, see Package Code for Other Development Environments (MATLAB Coder).