Matlab coder unable to compile MEX function with MinGW64 Compiler

Hello, I am trying to compile a Mex function for a model I've created, but for some reason despite updating, configuring and managing the MinGW compiler for Matlab, I cannot seem to get it working properly anymore.
I start up Matlab Codegen, run through the requested steps, but Matlab keeps failing at the "Check for Run-Time Issues" part when it has to generate a Mex. More specifically this is the error I get:
[291/291] C:\ProgramData\MATLAB\SupportPackages\R2020b\3P.instrset\mingw_w64.instrset\bin\gcc @SDM_main_mex.mexw64.rsp -m64 -Wl,--no-undefined -shared -static -L"C:\Program Files\MATLAB\R2020b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -o "SDM_main_mex.mexw64" -llibemlrt -llibcovrt -llibut -llibmwmathutil "C:/Users/marco/Dropbox/RFI - SDM Marco/SDM/Modelli\BaseSw.lib" "ws2_32.lib" "C:/Users/marco/Dropbox/RFI - SDM Marco/SDM/Modelli\CFM.lib" "C:/Users/marco/Dropbox/RFI - SDM Marco/SDM/Modelli\SFM.lib" -Wl,--version-script,SDM_main_mex.map
FAILED: SDM_main_mex.mexw64 
C:\ProgramData\MATLAB\SupportPackages\R2020b\3P.instrset\mingw_w64.instrset\bin\gcc @SDM_main_mex.mexw64.rsp -m64 -Wl,--no-undefined -shared -static -L"C:\Program Files\MATLAB\R2020b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -o "SDM_main_mex.mexw64" -llibemlrt -llibcovrt -llibut -llibmwmathutil "C:/Users/marco/Dropbox/RFI - SDM Marco/SDM/Modelli\BaseSw.lib" "ws2_32.lib" "C:/Users/marco/Dropbox/RFI - SDM Marco/SDM/Modelli\CFM.lib" "C:/Users/marco/Dropbox/RFI - SDM Marco/SDM/Modelli\SFM.lib" -Wl,--version-script,SDM_main_mex.map
gcc: error: ws2_32.lib: No such file or directory
ninja: build stopped: subcommand failed.
I have tried running it on both R2020b and R2021b, I've followed the steps present in https://www.mathworks.com/matlabcentral/answers/313298-i-already-have-mingw-on-my-computer-how-do-i-configure-it-to-work-with-matlab as well to no avail. I don't really get why it suddenly refuses to cooperate anymore, as I was previously able to generate Mex functions no problem.

4 Commenti

The information that I find is that you need Visual Studio C++ for that library, and also that MinGW would use ws_32.a not ws_32.lib
Running
mex -setup
and selecting Microsoft Visual C++ 2022 (C) in place of MinGW does not seem to work either: Codegen just returns me an error stating that MVC++ is not suited for Mex generation. Is there another package I should be installing? I have updated all versions of Microsoft Visual C++ I could get working on my laptop, but they still do not show up in Matlab.
You need VS2019 instead of VS2022
Worked like a cinch! I should also add to this though that the issue seems to be something that also relates to Matlab R2021b. Running Codegen with Matlab R2020b + VisualStudio 2019 fixed it! Thanks!

Accedi per commentare.

Risposte (0)

Prodotti

Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by