Error '.mexw64 is not a valid Win32 application' while building a Simulink model with S-function blocks.

I am working on porting an old MATLAB 7.1 32bit Simulink library to a newer MATLAB version (MATLAB 2022 64bit). This library utilizes S-function blocks.
In the old library version, these S-functions referenced some .dll files generated from source .c files using the MATLAB mex command.
To be able to use the library in MATLAB 2022, I attempted to recompile the source .c files with the mex command, and they now have the .mexw64 extension.
I also recompiled the .lib libraries on which these .c files depend using Visual Studio 2022, ensuring they are compatible with 64-bit programs. I provided them as inputs during the mex function calls (with the arguments -I, -L, and -l).
For example this is how i generate the .mexw64 file for a call_simul_mng.c file:
mex -v -I.\..\..\..\libraries\dsp_base_sw\include ...
-LC:\Users\522397\source\repos\mclk_lib\x64\Release ...
-lmclk_lib.lib ...
-I.\..\..\..\libraries\var_db_lib\src ...
-LC:\Users\522397\source\repos\var_db_lib\x64\Release ...
-lvar_db_lib.lib ...
call_simul_mng.c
where the mclk_lib.lib and var_db_lib.lib libraries are the ones i recompiled on visual studio 2022.
However, when I open a model that uses the library blocks and try to use the 'Update Model' command on the Simulink toolstrip to check if the model can compile and simulate, I encounter the following error: 'XXX.mexw64 is not a valid Win32 application', where XXX is the name of the S-function executable.
Can anyone help me?

 Accepted Answer

I discovered that while generating the mexw64, the main object file was being linked to the original 32-bit version of the libraries.
This occurred because the path to those libraries was saved in the Windows PATH environment variable, which was overriding the path I provided as an argument to the mex function.
By modifying the environment variable to point to the new library paths, I was able to successfully generate the 64-bit mexw64 files and resolve the errors.

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products

Release

R2022b

Asked:

on 6 Dec 2024

Answered:

on 9 Dec 2024

Community Treasure Hunt

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

Start Hunting!