How to include a directory along with subfolders in a including path of "code importer wizard"

40 views (last 30 days)
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
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
Leelakrishna Jonnadula on 18 Nov 2022
Shivam,
Thank you for the great suggestion! I endend up seeing below error even though matlab has identified the compiler. It would be a great help if you could through some light on this problem.
>> mex -setup -v c++
Verbose mode is on.
... Looking for compiler 'Intel Parallel Studio XE 2018 for C++ with Microsoft Visual Studio 2015' ...
... Looking for environment variable 'ICPP_COMPILER18' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2018 for C++ with Microsoft Visual Studio 2015'.
... Looking for compiler 'Intel Parallel Studio XE 2018 for C++ with Microsoft Visual Studio 2017' ...
... Looking for environment variable 'ICPP_COMPILER18' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2018 for C++ with Microsoft Visual Studio 2017'.
... Looking for compiler 'Intel Parallel Studio XE 2018 for C++ with Microsoft Visual Studio 2019' ...
... Looking for environment variable 'ICPP_COMPILER18' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2018 for C++ with Microsoft Visual Studio 2019'.
... Looking for compiler 'Intel Parallel Studio XE 2019 for C++ with Microsoft Visual Studio 2015' ...
... Looking for environment variable 'ICPP_COMPILER19' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2019 for C++ with Microsoft Visual Studio 2015'.
... Looking for compiler 'Intel Parallel Studio XE 2019 for C++ with Microsoft Visual Studio 2017' ...
... Looking for environment variable 'ICPP_COMPILER19' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2019 for C++ with Microsoft Visual Studio 2017'.
... Looking for compiler 'Intel Parallel Studio XE 2019 for C++ with Microsoft Visual Studio 2019' ...
... Looking for environment variable 'ICPP_COMPILER19' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2019 for C++ with Microsoft Visual Studio 2019'.
... Looking for compiler 'Intel Parallel Studio XE 2020 for C++ with Microsoft Visual Studio 2017' ...
... Looking for environment variable 'ICPP_COMPILER20' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2020 for C++ with Microsoft Visual Studio 2017'.
... Looking for compiler 'Intel Parallel Studio XE 2020 for C++ with Microsoft Visual Studio 2019' ...
... Looking for environment variable 'ICPP_COMPILER20' ...No.
Did not find installed compiler 'Intel Parallel Studio XE 2020 for C++ with Microsoft Visual Studio 2019'.
... Looking for compiler 'Intel oneAPI 2021 for C++ with Microsoft Visual Studio 2017' ...
... Looking for environment variable 'ONEAPI_ROOT' ...No.
... Looking for environment variable 'ONEAPI_ROOT' ...No.
Did not find installed compiler 'Intel oneAPI 2021 for C++ with Microsoft Visual Studio 2017'.
... Looking for compiler 'Intel oneAPI 2021 for C++ with Microsoft Visual Studio 2019' ...
... Looking for environment variable 'ONEAPI_ROOT' ...No.
... Looking for environment variable 'ONEAPI_ROOT' ...No.
Did not find installed compiler 'Intel oneAPI 2021 for C++ with Microsoft Visual Studio 2019'.
... Looking for compiler 'MinGW64 Compiler (C++)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset').
... Looking for file 'C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset\bin\g++.exe' ...Yes.
... Looking for folder 'C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset' ...Yes.
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset').
... Executing command 'C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset\bin\g++ -dumpmachine' ...Yes ('x86_64-w64-mingw32').
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset').
... Executing command 'C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset\bin\g++ -dumpversion' ...Yes ('6.3.0').
Found installed compiler 'MinGW64 Compiler (C++)'.
... Looking for compiler 'MinGW64 Compiler with Windows 10 SDK or later (C++)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset').
... Looking for file 'C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset\bin\g++.exe' ...Yes.
... Looking for folder 'C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset' ...Yes.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder ...No.
Did not find installed compiler 'MinGW64 Compiler with Windows 10 SDK or later (C++)'.
... Looking for compiler 'Microsoft Visual C++ 2015' ...
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
Did not find installed compiler 'Microsoft Visual C++ 2015'.
... Looking for compiler 'Microsoft Visual C++ 2017' ...
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
Did not find installed compiler 'Microsoft Visual C++ 2017'.
... Looking for compiler 'Microsoft Visual C++ 2019' ...
... Looking for environment variable 'ProgramFiles(x86)' ...Yes ('C:\Program Files (x86)').
... Looking for file 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' ...No.
... Looking for environment variable 'ProgramFiles(x86)' ...Yes ('C:\Program Files (x86)').
... Looking for file 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' ...No.
... Looking for environment variable 'ProgramFiles(x86)' ...Yes ('C:\Program Files (x86)').
... Looking for file 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' ...No.
Did not find installed compiler 'Microsoft Visual C++ 2019'.
... Looking for compiler 'Microsoft Visual C++ 2022' ...
... Looking for environment variable 'ProgramFiles(x86)' ...Yes ('C:\Program Files (x86)').
... Looking for file 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' ...No.
... Looking for environment variable 'ProgramFiles(x86)' ...Yes ('C:\Program Files (x86)').
... Looking for file 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' ...No.
... Looking for environment variable 'ProgramFiles(x86)' ...Yes ('C:\Program Files (x86)').
... Looking for file 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' ...No.
Did not find installed compiler 'Microsoft Visual C++ 2022'.
... Looking for compiler 'MinGW64 Compiler (C++)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset').
... Looking for file 'C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset\bin\g++.exe' ...Yes.
... Looking for folder 'C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset' ...Yes.
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset').
... Executing command 'C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset\bin\g++ -dumpmachine' ...Yes ('x86_64-w64-mingw32').
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset').
... Executing command 'C:\ProgramData\MATLAB\SupportPackages\R2022b\3P.instrset\mingw_w64.instrset\bin\g++ -dumpversion' ...Yes ('6.3.0').
Found installed compiler 'MinGW64 Compiler (C++)'.
MEX configured to use 'MinGW64 Compiler (C++)' for C++ language compilation.
Shivam Malviya
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:
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

Sign in to comment.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!