Dynamic linking of objects in external libraries with systems in MLDesigner is possible. This is a useful feature if you want to include functions from a variety of different libraries without rewriting the function.
These objects encompass object files (.o), static libraries (.a), and shared objects (.so or .dll). MLDesigner checks to see if the object files exist in the specified directory. With previous versions of MLDesigner it was only possible to link precompiled objects. Now if the specified files no longer exist MLDesigner will look for a makefile in the location where the object files were specified. If a makefile does not exist you must create it in the correct location. MLDesigner will then compile the object files thus ensuring that any changes made to the object are updated.
You can dynamically link on a primitive level where the function defined in the external library is defined as extern in a code item of the primitive source before being called in the go method. You can also link on a system level where an external library is defined.
For this example we need to create a small system containing two Ramp primitives, a user defined add primitive and a dump primitive to write the simulation results to a file. This system can be found at MLD Examples→Tutorials→Dynamic Linking→DynamicLinking.
You must now create the add primitive called AddExt:
You must now open the primitives source code and modify the code manually to look like the following:
ccinclude {} code { extern int externalLibraryAdd( int, int ); } constructor { }
The primitive now tells the parser to look in an external library for the described function. The next step is to describe the behavior of the primitive during simulation, that is, call the function of the external library.
go { int a = (int)(Input1%0); int b = (int)(Input2%0); int c = externalLibraryAdd( a, b ); Output1%0 << c; }
The next step is to show MLDesigner where the external file is physically saved.
The next step is to add the dump primitive to write the simulation results to a file.
It is important in to pay attention to the order in which linked objects are used by a system when the system is being simulated Extern. The objects should be listed in the correct order otherwise the simulation will not run. To change the order in which linked objects are listed, select the appropriate object in the Select Multiple Files dialog of the Linked Objects property and move the object Up or Down in the list.
Currently this feature is only available in MLDesigner on Linux.
Permanently loading code when entering Simulation Mode in order to extend the functionality of MLDesigner such as including a new domain or your own interface for interaction with other tools for co-simulation is possible.Open the file $HOME/.mld/.ptclshrc, it should be present if you have switched to Simulation Mode at least once. You will see place holders for filenames with extension .o (object files), .a (static libraries), and .so (shared objects). You must enter the full path of the file you wish to dynamically link to MLDesigner in the appropriate place holder. Before these setting become active you need to re-enter Simulation Mode.