Relocate Code to Another Development Environment with packNGo

Use the code generator packNGo option to generate code in one location. After code generation, collect the compiler command-line options, move the generated code to another location, and compile the generated code in combination with custom code.

Check Platform and Set Up Path and Folders

For this example, you must have the gcc toolchain running on a Linux® platform. After verifying this platform, this example sets up the path, folders, and files.

When you rerun the example, to ease clean up of generated files, the work folders (code_generation_area_dir and build_area_dir) are separate from the source files (models_dir and hand_code_dir).

All locations of source file and folders use paths that are relative to the folder containing the example .M file.

if ismac
    % Code to run on Mac platform
	disp('Platform (Macintosh) not supported.')
elseif ispc
    % Code to run on Windows platform
	disp('Platform (Windows) not supported.')
elseif isunix
originalFolder = pwd;
thisFilesFullName = mfilename( 'fullpath' );
thisFilesAbsolutePath = fileparts( thisFilesFullName );
modelsFolder = fullfile( thisFilesAbsolutePath, 'models_dir' );
codeGenerationRootFolder = ...
	fullfile( thisFilesAbsolutePath, 'code_generation_area_dir' );
buildAreaRootFolder = ...
	fullfile( thisFilesAbsolutePath, 'build_area_dir' );
handCodeFolder = ...
	fullfile( thisFilesAbsolutePath, 'hand_code_dir' );

Clean Up

To eliminate build artifacts from previously running the example, this example searches for and eliminates folders containing these by-products of previous runs.

if( 0 < exist( codeGenerationRootFolder, 'dir' ) )
	clear mex;
	rmdir( codeGenerationRootFolder, 's' );
else
% No previous codeGenerationRootFolder.
end
mkdir( codeGenerationRootFolder );

if( 0 < exist( buildAreaRootFolder, 'dir' ) )
	clear mex;
	rmdir( buildAreaRootFolder, 's' );
else
% No previous buildAreaRootFolder.
end
mkdir( buildAreaRootFolder );
if( 0 < exist( modelsFolder, 'dir' ) )
	clear mex;
	rmdir( modelsFolder, 's' );
else
% No previous modelsFolder.
end
mkdir( modelsFolder );
copyfile((fullfile(matlabroot,'toolbox','rtw','rtwdemos','rtwdemo_packngo.slx')), ...
    (fullfile(modelsFolder,'rtwdemo_packngo.slx')),'f');
if( 0 < exist( handCodeFolder, 'dir' ) )
	clear mex;
	rmdir( handCodeFolder, 's' );
else
% No previous handCodeFolder.
end
mkdir( handCodeFolder );
copyfile((fullfile(matlabroot,'toolbox','rtw','rtwdemos','rtwdemo_packngo','main.c')), ...
    (fullfile(handCodeFolder,'main.c')),'f');
copyfile((fullfile(matlabroot,'toolbox','rtw','rtwdemos','rtwdemo_packngo','main.h')), ...
    (fullfile(handCodeFolder,'main.h')),'f');
directoriesToAddToMatlabPathCellStr = ...
	{ ...
	thisFilesAbsolutePath, ...
	modelsFolder ...
	};
for directoryIndex = 1 : numel( directoriesToAddToMatlabPathCellStr )
    currentDirectory = directoriesToAddToMatlabPathCellStr{ directoryIndex };
    addpath( currentDirectory );
end

Generate Code and Output a .zip File with packNGo

In this example, the code generation configuration for the rtwdemo_packngo model enables the Generate code only parameter (GenCodeOnly) and enables the Package code and artifacts parameter (PackageGeneratedCodeAndArtifacts). These options direct the code generator to create a packNGo archive (.zip file) and stop the build process without compiling the generated code. Compilation occurs later with integrated custom code that replaces the generated main.c file.

cd( codeGenerationRootFolder );
modelBaseName = 'rtwdemo_packngo';
open_system( modelBaseName );
slbuild( modelBaseName );
close_system( modelBaseName );
### Starting build procedure for: rtwdemo_packngo
### Successful completion of code generation for: rtwdemo_packngo

Extract Build Information from Makefile

When using the toolchain approach for the build process, you can extract build information from the generated makefile. The information includes source files, dependency files, and macro definitions and values that appear in the makefile. With current working folder set to the folder containing the generated makefile, rtwdemo_packngo.mk, in the Command Window, type:

cd( 'rtwdemo_packngo_grt_rtw' );
system('gmake -f rtwdemo_packngo.mk info')
gmake[5]: Entering directory '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/code_generation_area_dir/rtwdemo_packngo_grt_rtw'
### PRODUCT = ../rtwdemo_packngo
### PRODUCT_TYPE = executable
### BUILD_TYPE = Top-Level Standalone Executable
### INCLUDES = -I/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/code_generation_area_dir -I/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/code_generation_area_dir/rtwdemo_packngo_grt_rtw -I/mathworks/devel/bat/BR2020ad/build/matlab/extern/include -I/mathworks/devel/bat/BR2020ad/build/matlab/simulink/include -I/mathworks/devel/bat/BR2020ad/build/matlab/rtw/c/src -I/mathworks/devel/bat/BR2020ad/build/matlab/rtw/c/src/ext_mode/common -I/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/code_generation_area_dir/slprj/grt/_sharedutils
### DEFINES = -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DMAT_FILE=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0  -DTID01EQ=0 -DMODEL=rtwdemo_packngo -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DRT -DUSE_RTMODEL
### ALL_SRCS = /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/code_generation_area_dir/rtwdemo_packngo_grt_rtw/rtwdemo_packngo.c /mathworks/devel/bat/BR2020ad/build/matlab/rtw/c/src/common/rt_main.c
### ALL_OBJS = rtwdemo_packngo.o rt_main.o
### LIBS = 
### MODELREF_LIBS = 
### SYSTEM_LIBS = -lm
### TOOLCHAIN_LIBS = 
### CFLAGS = -c -fwrapv -ansi -pedantic -Wno-long-long -fPIC -O0 -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DMAT_FILE=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0  -DTID01EQ=0 -DMODEL=rtwdemo_packngo -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DRT -DUSE_RTMODEL -I/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/code_generation_area_dir -I/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/code_generation_area_dir/rtwdemo_packngo_grt_rtw -I/mathworks/devel/bat/BR2020ad/build/matlab/extern/include -I/mathworks/devel/bat/BR2020ad/build/matlab/simulink/include -I/mathworks/devel/bat/BR2020ad/build/matlab/rtw/c/src -I/mathworks/devel/bat/BR2020ad/build/matlab/rtw/c/src/ext_mode/common -I/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/code_generation_area_dir/slprj/grt/_sharedutils
### LDFLAGS = -Wl,-rpath,/mathworks/devel/bat/BR2020ad/build/matlab/bin/glnxa64,-L/mathworks/devel/bat/BR2020ad/build/matlab/bin/glnxa64
### SHAREDLIB_LDFLAGS = -shared -Wl,-rpath,/mathworks/devel/bat/BR2020ad/build/matlab/bin/glnxa64,-L/mathworks/devel/bat/BR2020ad/build/matlab/bin/glnxa64 -Wl,--no-undefined
### CPPFLAGS = -c -fwrapv -std=c++03 -pedantic -Wno-long-long -fPIC -O0 -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DMAT_FILE=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0  -DTID01EQ=0 -DMODEL=rtwdemo_packngo -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DRT -DUSE_RTMODEL -I/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/code_generation_area_dir -I/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/code_generation_area_dir/rtwdemo_packngo_grt_rtw -I/mathworks/devel/bat/BR2020ad/build/matlab/extern/include -I/mathworks/devel/bat/BR2020ad/build/matlab/simulink/include -I/mathworks/devel/bat/BR2020ad/build/matlab/rtw/c/src -I/mathworks/devel/bat/BR2020ad/build/matlab/rtw/c/src/ext_mode/common -I/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/code_generation_area_dir/slprj/grt/_sharedutils
### CPP_LDFLAGS = -Wl,-rpath,/mathworks/devel/bat/BR2020ad/build/matlab/bin/glnxa64,-L/mathworks/devel/bat/BR2020ad/build/matlab/bin/glnxa64
### CPP_SHAREDLIB_LDFLAGS = -shared -Wl,-rpath,/mathworks/devel/bat/BR2020ad/build/matlab/bin/glnxa64,-L/mathworks/devel/bat/BR2020ad/build/matlab/bin/glnxa64 -Wl,--no-undefined
### ARFLAGS = ruvs
### MEX_CFLAGS = 
### MEX_CPPFLAGS = 
### MEX_LDFLAGS = 
### MEX_CPPLDFLAGS = 
### DOWNLOAD_FLAGS = 
### EXECUTE_FLAGS = 
### MAKE_FLAGS = -f rtwdemo_packngo.mk
gmake[5]: Leaving directory '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/code_generation_area_dir/rtwdemo_packngo_grt_rtw'

ans =

     0

For information about performing a similar operation on Windows® platforms, see the model.bat description in Manage Build Process Files (Simulink Coder).

Move Generated Code and Custom Code to Common Location for Build Process

To integrate the generated code and custom code, this example moves the files to a common location for the build process. The archive from the packNGo option is unzipped.

cd( buildAreaRootFolder );
generatedPackNGoArchiveShortName = ...
	[ modelBaseName, '.zip' ];
filesToCopyCellStr = ...
	{ ...
	fullfile( codeGenerationRootFolder, generatedPackNGoArchiveShortName ), ...
	fullfile( handCodeFolder, 'main.h' ), ...
	fullfile( handCodeFolder, 'main.c' ) ...
	};
fileCopyFunctionHandle = ...
	@( sourceFileFullName )copyfile( sourceFileFullName, buildAreaRootFolder );
for sourceFileIndex = 1 : numel( filesToCopyCellStr )
    currentSourceFile = filesToCopyCellStr{ sourceFileIndex };
    fileCopyFunctionHandle( currentSourceFile );
end
generatedPackNGoArchiveDestinationFullName = ...
	fullfile( buildAreaRootFolder, generatedPackNGoArchiveShortName );
unzip( generatedPackNGoArchiveDestinationFullName );

Construct the Build Command

To compile the generated code and integrated custom code, this example constructs a build command for the gcc compiler and tools that:

  • Compiles the generated and custom source files

  • Specifies the required folders where the preprocessor can locate included header files

  • Provides the correct -D arguments for preprocessor macros that the generated code requires

Identify the Source Files for the Build Command

The generated source files are in a folder extracted from the packNGo archive (.zip file). The file name combines the:

  • Model name

  • System target file (selected in the model configuration set)

  • Original code generation folder

generatedCodeSubFolderName = ...
	[ modelBaseName, '_grt_rtw' ];
generatedCodeFolderFullName = ...
	fullfile( buildAreaRootFolder, 'code_generation_area_dir', generatedCodeSubFolderName );
sharedCodeFolderFullName = fullfile( buildAreaRootFolder, 'code_generation_area_dir', 'slprj', 'grt', '_sharedutils');
sourceFileFullNamesCellStr = ...
	{ ...
	fullfile( buildAreaRootFolder, 'main.c' ), ...
	fullfile( generatedCodeFolderFullName, 'rtwdemo_packngo.c' ) ...
	};

Identify the Header File Folders

The required header file folders include:

  • Custom header file locations

  • Generated header file locations

  • Locations that contain files that the packNGo operation copied from the MATLAB installation folders to the packNGo archive

[ ~, matlabReleaseFolderName ] = fileparts( matlabroot() );
headerFileDirectoriesCellStr = ...
	{ ...
	buildAreaRootFolder, ...
	generatedCodeFolderFullName, ...
    sharedCodeFolderFullName, ...
	fullfile( buildAreaRootFolder, matlabReleaseFolderName, 'extern', 'include' ), ...
	fullfile( buildAreaRootFolder, matlabReleaseFolderName, 'simulink', 'include' ) ...
	};

Identify Required Preprocessor Macros

There are a number of preprocessor macros that must be defined to guide conditional compilation in the code. The macro names and values can be copied from the defines.txt file in the generated code folder.

commandLineDefinesCellStr = ...
	{ ...
	'MODEL=rtwdemo_packngo', ...
	'NUMST=1', ...
	'NCSTATES=0', ...
	'HAVESTDIO', ...
	'RT', ...
	'USE_RTMODEL', ...
	'UNIX', ...
	'MAT_FILE=0', ...
	'INTEGER_CODE=0', ...
	'MT=0', ...
	'CLASSIC_INTERFACE=0', ...
	'ALLOCATIONFCN=0', ...
	'ONESTEPFCN=1', ...
	'TERMFCN=1', ...
	'MULTI_INSTANCE_CODE=0', ...
	'TID01EQ=0' ...
	};

Prepare Cell Array Data as Strings

After gathering the source, header, folder, and macro information for the build command into cell array data, this example constructs the build command by reorganizing this data as properly-formed strings. The strings serve as part of a compilation command.

commandLineDefinesCompilerArgumentString = ...
	strjoin( strcat( '-D', commandLineDefinesCellStr ), ' ' );
sourceFilesCompilerArgumentString = ...
    ['"' strjoin( sourceFileFullNamesCellStr, '" "' ) '"'];
inclusionDirectoriesCompilerArgumentString = ...
    ['-I"' strjoin(headerFileDirectoriesCellStr, '" -I"') '"'];
compilationCommandString = ...
	[ ...
	'gcc', ' ', ...
	'-v', ' ', ...
	sourceFilesCompilerArgumentString, ' ', ...
	commandLineDefinesCompilerArgumentString, ' ', ...
	inclusionDirectoriesCompilerArgumentString ...
	];

Run the Compilation Command

The compilation command is:

[ compilationResult, compilationOutput ] = ...
	system( compilationCommandString );

View the Compilation Results

The results use operating system conventions for the return values because "system(...)" returns the results from the operating system. As a result, "0" indicates success, instead of "1"/"true.

assert( ( 0 == compilationResult ), compilationOutput );
disp( compilationOutput );
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/6.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /mathworks/devel/sandbox/rjarrett/3p-internal/3p/sources/gcc-6.3/configure --with-gmp=/mathworks/devel/sandbox/rjarrett/3p-internal/3p/derived/glnxa64/gcc-6.3/gmp-4.3 --with-mpfr=/mathworks/devel/sandbox/rjarrett/3p-internal/3p/derived/glnxa64/gcc-6.3/mpfr --with-mpc=/mathworks/devel/sandbox/rjarrett/3p-internal/3p/derived/glnxa64/gcc-6.3/mpc --enable-languages=c,c++,fortran --with-bugurl=http://inside.mathworks.com/wiki/Suspected_compiler_bugs,_Debugging --enable-shared --enable-linker-build-id --enable-plugin --enable-checking=release --enable-multiarch --enable-gold --enable-ld=default --enable-libstdcxx-time=no --prefix=/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0 --with-pkgversion='MW GCC 6.3.0-GLIBC2.12-gold' --with-tune=generic --with-system-zlib --enable-multilib --with-multilib-list=m32,m64 --with-arch-directory=amd64 --with-arch-32=i586 --with-abi=m64
Thread model: posix
gcc version 6.3.0 (MW GCC 6.3.0-GLIBC2.12-gold) 
COLLECT_GCC_OPTIONS='-v' '-D' 'MODEL=rtwdemo_packngo' '-D' 'NUMST=1' '-D' 'NCSTATES=0' '-D' 'HAVESTDIO' '-D' 'RT' '-D' 'USE_RTMODEL' '-D' 'UNIX' '-D' 'MAT_FILE=0' '-D' 'INTEGER_CODE=0' '-D' 'MT=0' '-D' 'CLASSIC_INTERFACE=0' '-D' 'ALLOCATIONFCN=0' '-D' 'ONESTEPFCN=1' '-D' 'TERMFCN=1' '-D' 'MULTI_INSTANCE_CODE=0' '-D' 'TID01EQ=0' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/rtwdemo_packngo_grt_rtw' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/slprj/grt/_sharedutils' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/extern/include' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/simulink/include' '-mtune=generic' '-march=x86-64'
 /mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/6.3.0/cc1 -quiet -v -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/rtwdemo_packngo_grt_rtw -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/slprj/grt/_sharedutils -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/extern/include -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/simulink/include -imultiarch x86_64-linux-gnu -iprefix /mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/ -D MODEL=rtwdemo_packngo -D NUMST=1 -D NCSTATES=0 -D HAVESTDIO -D RT -D USE_RTMODEL -D UNIX -D MAT_FILE=0 -D INTEGER_CODE=0 -D MT=0 -D CLASSIC_INTERFACE=0 -D ALLOCATIONFCN=0 -D ONESTEPFCN=1 -D TERMFCN=1 -D MULTI_INSTANCE_CODE=0 -D TID01EQ=0 /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/main.c -quiet -dumpbase main.c -mtune=generic -march=x86-64 -auxbase main -version -o /tmp/BR2020ad_1302590_239645/publish_examples4/ccCKMUWv.s
GNU C11 (MW GCC 6.3.0-GLIBC2.12-gold) version 6.3.0 (x86_64-pc-linux-gnu)
	compiled by GNU C version 6.3.0, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.2, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/include"
ignoring duplicate directory "/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/6.3.0/include"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring duplicate directory "/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/6.3.0/include-fixed"
ignoring nonexistent directory "/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir
 /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/rtwdemo_packngo_grt_rtw
 /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/slprj/grt/_sharedutils
 /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/extern/include
 /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/simulink/include
 /mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/include
 /mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/include-fixed
 /usr/local/include
 /mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/../../include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C11 (MW GCC 6.3.0-GLIBC2.12-gold) version 6.3.0 (x86_64-pc-linux-gnu)
	compiled by GNU C version 6.3.0, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.2, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: c26022ef40cbe05afcbd998c36f33b4e
COLLECT_GCC_OPTIONS='-v' '-D' 'MODEL=rtwdemo_packngo' '-D' 'NUMST=1' '-D' 'NCSTATES=0' '-D' 'HAVESTDIO' '-D' 'RT' '-D' 'USE_RTMODEL' '-D' 'UNIX' '-D' 'MAT_FILE=0' '-D' 'INTEGER_CODE=0' '-D' 'MT=0' '-D' 'CLASSIC_INTERFACE=0' '-D' 'ALLOCATIONFCN=0' '-D' 'ONESTEPFCN=1' '-D' 'TERMFCN=1' '-D' 'MULTI_INSTANCE_CODE=0' '-D' 'TID01EQ=0' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/rtwdemo_packngo_grt_rtw' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/slprj/grt/_sharedutils' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/extern/include' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/simulink/include' '-mtune=generic' '-march=x86-64'
 /mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/bin/as -v -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/rtwdemo_packngo_grt_rtw -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/slprj/grt/_sharedutils -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/extern/include -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/simulink/include --64 -o /tmp/BR2020ad_1302590_239645/publish_examples4/ccfF3ePL.o /tmp/BR2020ad_1302590_239645/publish_examples4/ccCKMUWv.s
GNU assembler version 2.28.1 (x86_64-pc-linux-gnu) using BFD version (GNU Binutils) 2.28.1
COLLECT_GCC_OPTIONS='-v' '-D' 'MODEL=rtwdemo_packngo' '-D' 'NUMST=1' '-D' 'NCSTATES=0' '-D' 'HAVESTDIO' '-D' 'RT' '-D' 'USE_RTMODEL' '-D' 'UNIX' '-D' 'MAT_FILE=0' '-D' 'INTEGER_CODE=0' '-D' 'MT=0' '-D' 'CLASSIC_INTERFACE=0' '-D' 'ALLOCATIONFCN=0' '-D' 'ONESTEPFCN=1' '-D' 'TERMFCN=1' '-D' 'MULTI_INSTANCE_CODE=0' '-D' 'TID01EQ=0' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/rtwdemo_packngo_grt_rtw' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/slprj/grt/_sharedutils' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/extern/include' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/simulink/include' '-mtune=generic' '-march=x86-64'
 /mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/6.3.0/cc1 -quiet -v -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/rtwdemo_packngo_grt_rtw -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/slprj/grt/_sharedutils -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/extern/include -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/simulink/include -imultiarch x86_64-linux-gnu -iprefix /mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/ -D MODEL=rtwdemo_packngo -D NUMST=1 -D NCSTATES=0 -D HAVESTDIO -D RT -D USE_RTMODEL -D UNIX -D MAT_FILE=0 -D INTEGER_CODE=0 -D MT=0 -D CLASSIC_INTERFACE=0 -D ALLOCATIONFCN=0 -D ONESTEPFCN=1 -D TERMFCN=1 -D MULTI_INSTANCE_CODE=0 -D TID01EQ=0 /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/rtwdemo_packngo_grt_rtw/rtwdemo_packngo.c -quiet -dumpbase rtwdemo_packngo.c -mtune=generic -march=x86-64 -auxbase rtwdemo_packngo -version -o /tmp/BR2020ad_1302590_239645/publish_examples4/ccCKMUWv.s
GNU C11 (MW GCC 6.3.0-GLIBC2.12-gold) version 6.3.0 (x86_64-pc-linux-gnu)
	compiled by GNU C version 6.3.0, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.2, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/include"
ignoring duplicate directory "/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/6.3.0/include"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring duplicate directory "/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/6.3.0/include-fixed"
ignoring nonexistent directory "/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir
 /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/rtwdemo_packngo_grt_rtw
 /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/slprj/grt/_sharedutils
 /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/extern/include
 /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/simulink/include
 /mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/include
 /mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/include-fixed
 /usr/local/include
 /mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/../../include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C11 (MW GCC 6.3.0-GLIBC2.12-gold) version 6.3.0 (x86_64-pc-linux-gnu)
	compiled by GNU C version 6.3.0, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.2, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: c26022ef40cbe05afcbd998c36f33b4e
COLLECT_GCC_OPTIONS='-v' '-D' 'MODEL=rtwdemo_packngo' '-D' 'NUMST=1' '-D' 'NCSTATES=0' '-D' 'HAVESTDIO' '-D' 'RT' '-D' 'USE_RTMODEL' '-D' 'UNIX' '-D' 'MAT_FILE=0' '-D' 'INTEGER_CODE=0' '-D' 'MT=0' '-D' 'CLASSIC_INTERFACE=0' '-D' 'ALLOCATIONFCN=0' '-D' 'ONESTEPFCN=1' '-D' 'TERMFCN=1' '-D' 'MULTI_INSTANCE_CODE=0' '-D' 'TID01EQ=0' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/rtwdemo_packngo_grt_rtw' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/slprj/grt/_sharedutils' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/extern/include' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/simulink/include' '-mtune=generic' '-march=x86-64'
 /mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/bin/as -v -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/rtwdemo_packngo_grt_rtw -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/slprj/grt/_sharedutils -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/extern/include -I /tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/simulink/include --64 -o /tmp/BR2020ad_1302590_239645/publish_examples4/cc786PM1.o /tmp/BR2020ad_1302590_239645/publish_examples4/ccCKMUWv.s
GNU assembler version 2.28.1 (x86_64-pc-linux-gnu) using BFD version (GNU Binutils) 2.28.1
COMPILER_PATH=/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/6.3.0/:/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../libexec/gcc/:/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/bin/
LIBRARY_PATH=/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/:/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/:/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../lib64/:/lib/x86_64-linux-gnu/:/lib/../lib64/:/usr/lib/x86_64-linux-gnu/:/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/lib/:/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-D' 'MODEL=rtwdemo_packngo' '-D' 'NUMST=1' '-D' 'NCSTATES=0' '-D' 'HAVESTDIO' '-D' 'RT' '-D' 'USE_RTMODEL' '-D' 'UNIX' '-D' 'MAT_FILE=0' '-D' 'INTEGER_CODE=0' '-D' 'MT=0' '-D' 'CLASSIC_INTERFACE=0' '-D' 'ALLOCATIONFCN=0' '-D' 'ONESTEPFCN=1' '-D' 'TERMFCN=1' '-D' 'MULTI_INSTANCE_CODE=0' '-D' 'TID01EQ=0' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/rtwdemo_packngo_grt_rtw' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/slprj/grt/_sharedutils' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/extern/include' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/simulink/include' '-mtune=generic' '-march=x86-64'
 /mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/6.3.0/collect2 -plugin /mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/6.3.0/liblto_plugin.so -plugin-opt=/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../libexec/gcc/x86_64-pc-linux-gnu/6.3.0/lto-wrapper -plugin-opt=-fresolution=/tmp/BR2020ad_1302590_239645/publish_examples4/cctXdkLh.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o /mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/crtbegin.o -L/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0 -L/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc -L/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../../../x86_64-pc-linux-gnu/lib -L/mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/../../.. /tmp/BR2020ad_1302590_239645/publish_examples4/ccfF3ePL.o /tmp/BR2020ad_1302590_239645/publish_examples4/cc786PM1.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /mathworks/hub/3rdparty/internal/3349624/glnxa64/gcc-6.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/6.3.0/crtend.o /usr/lib/x86_64-linux-gnu/crtn.o
COLLECT_GCC_OPTIONS='-v' '-D' 'MODEL=rtwdemo_packngo' '-D' 'NUMST=1' '-D' 'NCSTATES=0' '-D' 'HAVESTDIO' '-D' 'RT' '-D' 'USE_RTMODEL' '-D' 'UNIX' '-D' 'MAT_FILE=0' '-D' 'INTEGER_CODE=0' '-D' 'MT=0' '-D' 'CLASSIC_INTERFACE=0' '-D' 'ALLOCATIONFCN=0' '-D' 'ONESTEPFCN=1' '-D' 'TERMFCN=1' '-D' 'MULTI_INSTANCE_CODE=0' '-D' 'TID01EQ=0' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/rtwdemo_packngo_grt_rtw' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/code_generation_area_dir/slprj/grt/_sharedutils' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/extern/include' '-I' '/tmp/BR2020ad_1302590_239645/publish_examples4/tp5d193b4d/ex21882019/build_area_dir/matlab/simulink/include' '-mtune=generic' '-march=x86-64'

Call the Integrated, Compiled Executable

Running the compile executable produces this output:

[ executionResult, executionOutput ] = system( './a.out' );
assert( ( 0 == executionResult ), executionOutput );
disp( executionOutput );
cd( originalFolder );
Input:	1.000000	Output:	42.000000
Input:	2.000000	Output:	84.000000
Input:	3.000000	Output:	126.000000
Input:	4.000000	Output:	168.000000
Input:	5.000000	Output:	210.000000

Considerations for Relocating Code to Other Platforms or Toolchains

This example shows how to use packNGo to relocate code and integrate custom code with generated code. These techniques ease relocating generated code to other platforms (for example, Linux® to Windows®). The sections of this example that show how to construct the build command provide information that supports code relocation.

The build command on the target platform (for example, Microsoft Visual C/C++ MSVC on Windows®) is as close as possible to the build tool flags and definitions in the build command on the source platform (for example, gcc on Linux®). Some flags and definitions are required (for example, list of source and dependency files). Other flags are optional (for example, compiler optimizations vary among compilers).

else
    disp('Platform not supported.')
end