How to include a directory along with subfolders in a including path of "code importer wizard"
Show older comments
Hi,
I am Matlab/Simulink user for 15years. I attended MAB 2022 and I was impressed by "Code Importer" tool for C++ in Simulink. This addition is inline with my dream goal of testing handwritten code in Simulink environment so that we can better visualize the behavior before production. I tried integrate testing the legacy code using “code importer wizard” of Simulink, 2022b version and ran into numerous errors. I have thousands of files in the project. My main struggle currently is adding include paths manually. Tool complains one after one for "cannot find file". Tool doesn’t seem to look through the subdirectories. There are hundreds of folders in the project. Is there a way to include top directory along with subdirectories, so that I don't have to include paths every time tool complains?
Any replies would be highly appreciated.
Thanks,
Leela
Answers (1)
Shivam Malviya
on 18 Nov 2022
Hi Leelakrishna,
It is my understanding that you are using the Code Importer Wizard for importing the legacy code.
According to the description, the tool doesn't search for the files in the sub-directories of the specified directory.
As a workaround, you may check the following function;
function getIncSubDir(incDir)
% This function writes the paths of all the sub-directories into the
% text file
% Get cell array of relative paths to all the sub directories
incSubDir = getSubDir(incDir);
% Create a file to store the subdirectories
fileID = fopen('incSubDir.txt','w');
% Write all the subdirectories path into the file
fprintf(fileID, "%s\n", incSubDir{:});
end
The above function creates a text file containing the path to all the subdirectories.
The following workflow achieves the desired objective;
- Provide the path to the include directory as an input to this function.
getIncSubDir('.\include')
- Copy the text from the output text file.

- Paste it into the include "Include directories;" field of the Code Importer wizard.

I hope it helps!
Regards,
Shivam Malviya
2 Comments
Leelakrishna Jonnadula
on 18 Nov 2022
Shivam Malviya
on 24 Nov 2022
Hi Leelakrishna,
This error could be due to a corrupt installation of the MinGW compiler.
To solve this issue, please re-install MinGW:
- https://in.mathworks.com/matlabcentral/answers/313290-how-do-i-install-mingw-for-use-in-matlab
- https://in.mathworks.com/help/matlab/matlab_external/install-mingw-support-package.html
Then set it as compiler from the MATLAB Command Window:
>> mex -setup c++
You should then be able to build a MEX file.
If the issue is not solved, there may be incompatibilities with other compilers that have the same command. Removing those compilers should solve the issue.
Please mark the answer as accepted if it resolves your issue.
Please consider creating a new ML Answer question for a separate query.
I hope it helps!
Regards,
Shivam Malviya
Categories
Find more on MATLAB Support for MinGW-w64 C/C++ Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!