MBDyn sim suite
Building MBDyn bindings
Those instructions will built MBDyn as a service that can be controlled from Python. That's why the term of bindings is used. The first step will be to enter in the 'bindings' directory: # cd bindingsGetting MBDyn source
This package is based on the 1.2.7 version of MBDyn, just some modifications are done for running MBDyn in a script language philosophy. You can get the source there and save them in the current 'bindings' directory, as an alternative you can use the following line: # wget http://www.aero.polimi.it/~masarati/Download/mbdyn/mbdyn-1.2.7.tar.gzDecompress the archive
The following line assumes that you are in the current 'bindings' directory, the building process is not going to work otherwise. # tar xvzf mbdyn-1.2.7.tar.gzCustomize your build (optional)
You can edit it 'custom.py' for adjusting the construction options. The most important are surely the install locations for the optional executable (set in "BIN_PREFIX") and the mandatory shared library (set by the "LIB_PREFIX" variable). The defaults are:- BIN_PREFIX="/usr/bin"
- LIB_PREFIX="/usr/lib"
Configure the project
Run SCons for the configuration. # scons conf=1This process should create the files 'libs_config.pickle' in the current directory as well as 'mbconfig.h' and 'mbdefs.h' in the 'mbdyn-1.2.7/include' directory.
Getting the MBDyn Executable (Optional)
If you do not have it already, you can directly build the MBDyn executable. However the MBDyn configure script does it more completely, all the options are not present in the SCons script. But as its motivation was to turn MBDyn into a shared library, the building process was first studied. You can also build MBDyn by: # scons bin=1And then install it by: # sudo scons install
Replace of course the 'BIN_PREFIX' by the one that suits you. If you do not use the sudo command, it just means that you need to be administrator to install the executable in a system location. You can install it in your home if you prefer, but you will have to update your 'PATH' variable.
Getting the MBDyn Shared Library
From that step, the modifications of the MBDyn source will be applied. An extra 'SWIG' definition is passed to the compiler, moreover the directory containing the changes, 'swig_interface/mbdyn_modifications', is always given as the first include directory. The build process is achieved by: # scons lib=1(Developer note: the modified files are not built any more in the main shared library, but will be part of the swig module. Only the definitions, contained in the header files, are given to the building process. This approach has the advantage to work with a small module during development, avoiding longer delays in the SCons construction. As the SWIG module is dynamically linked to the MBDyn shared library, the needed symbols are found at run time. Once a mature code reached, everything could be compiled into one shared library. But it would be certainly of interest to have MBDyn split into several shared libraries.)
The installation will be performed by: # sudo scons install_lib
You can specify 'LIB_PREFIX' to the one that suits you but be sure to put it in a path where your system looks for dynamic libraries. If you do not use the sudo command, it just means that you need to be administrator to install the executable in a system location. As an user, you can always adjust 'LD_LIBRARY_PATH' for installing it in your home directory.
Building Python bindings
Now the bindings can be built, they will contain a SWIG interface as well as modified MBDyn sources. At the end, they are dynamically linked to the MBDyn shared library. # scons bindings=1This step will not install the bindings on your system but only copy the generated Python file and swig shared library to the main package. # scons install_ext
Test the build (optional)
If you want to test that everything went fine, test the generated swig module by: # ldd ../mbdyn/bindings/_swigModule.soIf none of the link is broken, the bindings are probably working. Else check that the shared library can be found and is correctly installed or report a bug, see the development part.
(Developer note: one of the Python way of work can here be grasped. The package will be loaded by the interpreter from a script. Loading such module, will also load all the libraries that are linked to it. A new problem is rising comparing to the current way to build the MBDyn executable. The MBDyn shared library could thus been loaded with libraries introduced by third part module of the user script. As a result some symbol definitions could conflict with unforeseen third part libraries. An unsolved problem has been met with Matplotlib that load many libraries. When the 'pylab' module is loaded with the 'mbdyn.bindings' one, the service fails while processing the input file because surprisingly the function 'strtod' does not work anymore.)
Back to the Python Package
This is time to install the package as MBDyn is now available as a Python service. Change the current directory: # cd ..Build and install the Python package.