1) Find the path to the MinGW-w64 g++ compiler.
If you have installed the MinGW-w64 compiler as a MATLAB Add-on, you can locate the root folder at the MATLAB Command Window. For example:
>> getenv('MW_MINGW64_LOC')
ans =
'C:\ProgramData\MATLAB\SupportPackages\R2021b\3P.instrset\mingw_w64.instrset'
In this example, the g++.exe compiler is located in
C:\ProgramData\MATLAB\SupportPackages\R2021b\3P.instrset\mingw_w64.instrset\bin
2) Add the path to the MinGW-w64 compiler to the system path.
At the Windows command prompt, add the path to the MinGW-w64 compiler to the system path. Using the example above,
set mingwpath=C:\ProgramData\MATLAB\SupportPackages\R2021b\3P.instrset\mingw_w64.instrset\bin
set PATH=
3) Build the shared libraries.
Navigate to the location of C++ source files, and run these commands to generate shared library from the source file source.cpp.
g++ -c source.cpp -o source.obj -std=c++11
g++ -shared -o source.dll source.obj -Wl,--out-implib,source.lib
These commands create the library files source.dll and source.lib.