MATLAB Answers

Generate code: source code or mex file ?

1 view (last 30 days)
Maria
Maria on 31 Jul 2020
Commented: Maria on 5 Aug 2020
Hi,
it has only been a few days since I am dealing with mex files.
I am using Matlab coder. I can convert my original m files without any problems, but now I've got a doubt on which "build type" to choose. I was, without thinking too much, selecting the "Source code". I got the .mexw64, and I run the function name_function_mex in my Matlab code.
I saw now that, based on the description, the source type "MEX" should be more suitable, because it is a compiled code to be run in Matlab. I also tried the "MEX" built type, and the only difference I see is that I get a lot more files in the generated mex-related folder.
So my question is: why did the "source code" work at all in my case? Since it was working in my Matlab code (I could call the name_function_mex function as any other functions), should I still consider the build type "MEX" for some special reason...?

  0 Comments

Sign in to comment.

Accepted Answer

Darshan Ramakant Bhat
Darshan Ramakant Bhat on 2 Aug 2020
From your description I am assuming that you are using coder app.
When the "build type" is "Source code" it is not suppose to generate any MEX files. The correct configuration to generate MEX is the "MEX" build type.
I had tried "Source Code" configuration with a simple example, but I did not get any MEX file generated. Please attach the .prj file along with all the input files so that I can try to reproduce this from my end.

  3 Comments

Maria
Maria on 4 Aug 2020
Thank you for your answer. At the moment, I cannot share the code, but I just tried again, and I got the codegen folder -> mex folder and lib folder. In the mex folder, there is another folder with the name of the function I used in Matlab coder. Inside this one, there are 2 folders (html and interface), and the .mexw64.
I will try to write a piece of code such that I can share it with you.
Darshan Ramakant Bhat
Darshan Ramakant Bhat on 5 Aug 2020
Ahh, Now I got what is happening.
There is an intermediate optional step called "Check for run-time issues". In this step Coder will generate a MEX file to check run-time issues. More details :
If you skip this step, the "mex" folder should not get generated (not recommended).
So this will create a "mex" folder inside codegen. The .mexw64 is cached inside this folder to avoid re-generation when no settings are changed. Note that this MEX will be generated with customized settings suitable for internal use of runtime issue checking.
When you choose "MEX" build type, a .mexw64 file will be generate outside the "codegen" folder. Please use this in your application.
Hope this will be helpful for you.
Maria
Maria on 5 Aug 2020
Now is clear! Perfect, now I understood! I will use the MEX build type. Thank you very much!

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!