MATLAB Answers

Handle the external reference in the DLL generation TLC files

26 views (last 30 days)
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 :)

  0 Comments

Sign in to comment.

Accepted Answer

Kaustubha Govind
Kaustubha Govind on 3 Jan 2013
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

Show 1 older comment
grapevine
grapevine on 4 Jan 2013
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
Kaustubha Govind
Kaustubha Govind on 4 Jan 2013
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.

Sign in to comment.

More Answers (0)