The following steps might be helpful in combining the code generated from two models and creating a single application:
1. For each model, go to "Configuration Parameters -> Code Generation -> Interface -> Software environment" and for "Shared code placement", select "Shared location".
This setting instructs the Real-Time Workshop to place common files in the "slprj" folder instead of the 'model_rtw' folder (All the utility functions used by both the models will be in the same directory, namely the _sharedutil directory in the slprj folder).
2. Build all the relevant models in the same directory where the "slprj" folder was created for the first model.
3. Copy all the files necessary for both models into one directory. 'packNGo' is useful for this purpose (Use packNGo function on each model, to get all the files that are necessary for the build process).
More information about this function can be found here:
4. Modify the makefile and the main program. The following templates can be used as a starting point:
a. Main template: MATLAB_ROOT/rtw/c/grt/classic_main.c
b. Make template: MATLAB_ROOT/rtw/c/grt_malloc/grt_msvc.tmf
Save the modified version as a single combine_main.c and combine_msvc.mk
Note: There should be comments with the word "Customize" for all the changes made .
Essentially, since there are going to be clashing defines, modify them to use separate names: i.e. NCSTATES1, NCSTATES2, etc.
5. Modify the BAT file
You can use nmake to compile and link using msvc, and those make commands are usually located in the model.bat file in the generated code folder. Copy one of the batch file and create a combine.bat
5. Run the batch file to compile and link:
Go up a level, and you should see combine.exe.