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

16 次查看(过去 30 天)
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.

回答(1 个)

Kaustubha Govind
Kaustubha Govind 2012-2-22
  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.

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by