From a user's perspective, the only thing to do in order to use a dynamic module in ns is to load it. After this operation, the module itself can be used exactly as if it had been embedded in the ns binary.
The loading of a dynamic module should be performed at the beginning of the tcl script used for the simulation. The loading consists of the following tcl instruction:
load libmodulename.so
where libmodulename.so
is the filename of the shared
library.
One thing we have to take care of is to use the right path to the library. Relative and absolute paths can be used for this purpose; e.g., respectively,
load ../src/.libs/libmodulename.so load /locale/baldo/lib/somethingelse.so
Note that you can just provide the file name without any path, if the path it resides in is in the LD_LIBRARY_PATH
environmental variable.
Also remember that the format of the shared libraries is OS-dependent: .so
libraries are found in unix systems, while for instance on cygwin you will need to use .dll
libraries, e.g.
load libmodulename.dll
with this respect, it is to be noted that also the actual name of the library file might change - for instance, the same library mentioned before would be called cygmodule-0.dll
when built using libtool on a cygwin system. Just remember to chek the actual filename if you load
command fails.
Finally, it should be noted that on cygwin the PATH
variable is used instead of the LD_LIBRARY_PATH
for the purpose of finding dynamic libraries when load
is called just with the library filename (without the complete path to it)2We note that, for libraries built using libtool (which is the method we propose in this document), when you install the library on cygwin - i.e., when you type make install
-, the dll
file gets installed in YOUR_PREFIX/bin
, and not in YOUR_PREFIX/lib
as you might expect. Therefore, you should add YOUR_PREFIX/bin
to your PATH
to make everything work smoothly.
Actually it was quite difficult to find out how this worked... I wandered on the internet for a considerable amount of time, until I found this message on the libtool mailing list which gave me the information I needed.