build a static library instead of a dynamic one with MEX compiler

17 views (last 30 days)
Hello
I m looking for an option of the mex compiler in order to produce a static mex file with all the code, that it needs, already inside it. which can substitute all the external references inside my c code with the real code from the external library.
i tried to do that because I created a mex file to put inside a 2ndlevel sfunction block mex file.c -l APP_Numerical and until now everything is fine the program works on Simulink (the option -l is there, because I made some references to an external library)
Then in order to use it in a real time simulator, I need to translate this model with Real-Time Workshop (now Simulink Coder), but when I attempt to do that I get an error from the linker, which cannot find an external reference; i tried to add this library to the matlab path, but it doesn't work, then I fix it adding the static path of this library (.lib) in the option of Real-Time Workshop.
Is that any way to avoid that? I don't work with the same computer all the time, sometimes I need to switch it with other guys. So everytimes that I need to rebuild the library I need to looking for this library inside the new computer and put its path in the option of Real-Time Workshop.
So I was wondering if there is a way to ask to the mex compiler to substitute all the external references with the real code from the external library. In this way instead to produce a dynamic library it will produce a static library with all the code that it needs already inside it.

Answers (1)

Kaustubha Govind
Kaustubha Govind on 22 Feb 2012
  1. It is not to make MEX-files static libraries, because MATLAB cannot dynamically load static libraries - your MEX-file would then need to be compiled in with the MATLAB executable itself.
  2. If you are linking against purely static libraries (it is also possible that your .lib file is only an import library for a DLL that is required at runtime), then the MEX-file already includes the library code in itself. I think the problem you are facing is because Real-Time Workshop (now Simulink Coder) generates standalone code for your model, which is separate from an already compiled MEX-file. At the time that this new code needs to be compiled, your libraries are needed. I can't think of a way you can get around this.
  3. You can add the "-l" option to the Simulink Coder compiler command by adding your libraries (along with their full path) to the Code Generation>Custom Code>Libraries section of the Confiuration Parameters window.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!