Handle the external reference in the DLL generation TLC files

Hello everyone,
I would like to have your opinions about how to solve this issue :
I made some libraries, which involve in several blocks, these ones are basically some sfunctions, which make calls to several external libraries (.lib file).
These libraries are going to be used by other folks to create some simulink models, which will be "transformed' in a DLL, by using Real-Time Workshop (former Simulink Coder) to perform several tests on a external device.
In order to compile the simulink model I have to link the external library used by the block of the library, by adding the name of the library to the compiling instructions of RTW I usually did that with this instruction
set_param(gcs,'CustomLibrary','P3_System_2.lib'
My advisor asks me to simplify the use of the libraries to the other team. He would like when someone adds a block to a model, the external library that is used by the block, will be automatically add to the options of Real-Time Workshop. My solution was to add this instruction
set_param(gcs,'CustomLibrary','P3_System_2.lib'
to the CopyFcn Callback of the block.
But that's not good enough for my purpose, because it's not the optimal solution for the maintenance of the blocks
So I started to study how Real-Time workshop works
I found these references
I understood the DLL generation performed by RTW is essentially controlling by three files that are system target file, template makefile and make command.
So inspiring by this example
I thought to modify the .tlc file (used to specify the system language target) by including in the code the libraries that are requested for the compilation of the model. So I thought to add on the top of the code this instruction
%include "P310_System_2.lib"
I didn't test yet this solution, because I'm not at laboratory and I didn't have the RTW license on my PC
So I would like to have your opinions about this solution, if this one could work, or I'm out-of-way and I should change approach
Every suggestions are welcome
thanks for reading and happy new year of course :)

 Accepted Answer

Are these blocks all S-functions? If yes, the right way to do this is to create a rtwmakecfg.m file and place it in the same folder as the S-function MEX-files. Adding your .lib files to makeInfo.linkLibsObjs will ensure that any model that uses your blocks will link against the required libraries.

4 Comments

yes, thanks a lot for your answer. They are all sfunctions. So that's good
Therefore, by using the rtwmakecfg.m file, RTW adds the paths to the external libraries for all the models; which use the mex file stored in the same directory as rtwmakecfg.m file.
Actually i have several libraries and they (and their associated mex files ) are placed in different folders.
for example I have two libraries (e.g. P2_System , P2_Algebra ) organize in this way
P2_System
-> P2_System.mdl
-> SFL2_Validant.c
-> SFL2_Validant.mex32
-> ........
P2_Algebra
-> P2_Algebra.mdl
-> SFL2_Addition.c
-> SFL2_Addition.mex32
-> ........
I guess for each of these folders I should create a rtwmakecfg.m file. Am I right?
When an user creates a new simulink model and he adds some blocks, belonging to the different libraries (above ones), and then he launches the DLL generation.
Do you think RTW will be able to resolve all the external links?
I can give me an answer by myself :)
I went to the laboratory and I tested the solution and it works. I created a rtwmakecfg.m file for each library folder
I used this one as template of rtwmakecfg.m file
As you suggested me, I only modified the assignment of this variable
makeInfo.linkLibsObjs = {};
by
makeInfo.linkLibsObjs = {'N:\Libraries\P2_System\P2_System.lib'};
But actually I prefer to avoid to use the full path of the library 'N:\Libraries\P2_System\P2_System.lib' for the assignment
So I tried to specify only the library name without the full path
makeInfo.linkLibsObjs = {'P2_System.lib'};
But the RTW returns an error because it can't find P2_System.lib although ''N:\Libraries\P2_System\' is in the Matlab path
So my solution was to add these instructions before the makeInfo.linkLibsObjs assignment
[folder, name, ext] = fileparts(mfilename('fullpath'));
lib2ADD=[folder,'\P2_SYSTEM.lib'];
and modify it in this way
makeInfo.linkLibsObjs = {lib2ADD};
It works but I'm still wondering why RTW wasn't able to find P2_System.lib library although ''N:\Libraries\P2_System\' was in the Matlab path
grapevine: Glad you were able to solve the issue! Regarding the library path not getting resolved - note that the compiling of C code is not actually done by MATLAB itself - MATLAB simply calls into a C-compiler (typically the one selected using "mex -setup") to compile the generated code. The C compiler knows nothing about the MATLAB path. The right way to inform the C compiler about library paths is to either set the complete path using makeInfo.linkLibsObjs, or use makeInfo.library different fields to specify the library name, path, etc.
great
thank you so much for the explanation

Sign in to comment.

More Answers (0)

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!