MATLAB: How to include dynamic library paths in the S-Function with Real-Time Workshop 7.4 (R2009b)

codedynamicgenerationmakefilepathsimulink coder

I am working with S-Functions which call 3rd party libraries in Real-Time Workshop.
Unfortunately the installation path of this 3rd pary software varies from machine to machine. Therefore, this command in the Real-Time Workshop configuration parameters does not work since it is a static path:
make_rtw S_FUNCTIONS_LIB=C:\Sirius\Control\Library\mislib\Debug\mislib.lib
Is there a way to add dynamic paths?

Best Answer

There are several methods for adding dynamic paths in S-Functions with Real-Time Workshop 7.4 (R2009b):
1) Relative:
You can specify relative paths to your working directory e.g.:
make_rtw make_rtw S_FUNCTIONS_LIB=.\Control\Library\mislib\Debug\mislib.lib
This method is effective if you always have the same installation path relative to your actual working directory.
2) With Windows Environment Variables:
If you add this line to the Real-Time Workshop configuration parameters:
make_rtw OPTS="%USERNAME%"
You will get this output when compiling (suppose USERNAME =thisname:
### Compiling C:\MATLAB\R2009b\rtw\c\src\rt_sim.c
... SNIP ... /fp:precise thisname -DUSE_RTMODEL /Od /Oy- -DMODEL
... SNIP ...
cl : Command line warning D9024 : unrecognized source file type 'thisname', object file assumed
cl : Command line warning D9027 : source file 'thisname' ignored
rt_sim.c
### Linking ...
As you can see the value of the environment variable USERNAME is added to the makefile.
Now if you want to specify a path to a lib for your S-Function you could use the following string (Please note that the environment variable TestVar needs to be created in your OS):
make_rtw S_FUNCTIONS_LIB=%TestVar%\myStuff\install\myLib\testlib.lib
Please note that if the environment variable does not exist this will lead to very cryptic compiler errors.
3) Concerning the customization of makefile's this part of the documentation is also a very powerful resource:
web([Dorothy '/toolbox/decoder/debt/f6296.html#f6334'])
<http://www.mathworks.com/access/helpdesk/help/toolbox/ecoder/det/f6296.html#6334>