libSBML MATLAB API  5.18.0
Accessing libSBML from software

Once the libSBML files are installed, you may need to take additional steps so that software applications can find the libSBML library files at run time. This section provides information about how to do that.

1. Setting your library search path

Installing libSBML puts copies of the libSBML native object files in appropriate destinations on your computer. (By "native object files", we mean files such as libsbml.so, libsbml.5.dylib, libsbml.dll, etc.) On Mac OS X, this should be enough; a software application should be able to find the libSBML library file(s) when it runs. On Linux and Windows, that may not be enough to let a software application find the libSBML library files—you may need to take additional steps. This may be the case even if your application can find other libSBML components such as the language-specific interface (e.g., the libSBML JAR file in the Java case, or the libsbml.py file in the Python case).

If your run-time environment and the run-time environment for your software applications do not know to look in the directory where libSBML was installed, programs that require libSBML will fail to run and report errors about being unable to find libSBML.

How to configure most Linux platforms

There are two common approaches to solving the problem under Linux.

  1. Using ldconfig: Run the program ldconfig as user 'root' on your computer. (Please consult the man page for ldconfig if this is unfamiliar.) This will configure the system for all users.
  2. Setting environment variables: Ensure that each user sets the environment variable LD_LIBRARY_PATH in their terminal shells. If you downloaded a ready-to-run libSBML installer, the default where the libSBML library is installed is /usr/local/lib. If you built libSBML yourself using CMake, the path consists of /lib appended to the value used for the CMAKE_INSTALL_PREFIX configuration variable. If you built libSBML using GNU make, the path is DIR/lib, where DIR is the value used for the configuration option --prefix=DIR.

    For example, suppose you used the default installation prefix /usr/local/. Then in csh-based command shells under Linux, you may have to set the variable as follows (perhaps in your .cshrc file):

    setenv LD_LIBRARY_PATH /usr/local/lib
    

How to configure Microsoft Windows platforms:

Set the PATH environment variable to include the directory of the libSBML native library. To set an environmental variable in Windows, use the System option in the Windows Control Panel.

2. Importing libSBML

The instructions for MATLAB depend on the operating system you are using.

MATLAB on Linux, Mac OS X and similar Unix-like systems

The installation directory is also the same one where the additional files TranslateSBML.extension, OutputSBML.extension and CheckAndConvert.m will have been placed. These files implement the MATLAB interface to libSBML. On Linux and Unix-based systems including Mac OS X, the LD_LIBRARY_PATH/DYLD_LIBRARY_PATH environment variable may need to be set in the terminal shell from which MATLAB is started prior to starting MATLAB. (Otherwise, MATLAB itself will not "see" the value of the variable.)

Important: some versions of MATLAB produced for Linux include a version of the stdc++ library that conflicts with the version provided by the operating system, causing a mystifying error when MATLAB tries to run or compile code involving libSBML. Please see the section in the Known Issues document for more information.

An additional step is necessary in the MATLAB environment itself: adding the same directory to the list of directories that MATLAB searches to find functions. If DIR is the directory where the libSBML shared library as well as TranslateSBML.extension, OutputSBML.extension, and CheckAndConvert.m have been installed, then the following MATLAB command must be executed:

addpath('DIR');

For example, suppose you are using an Intel-based Mac OS X system and you have configured libSBML to install itself into /usr/local. Then the files TranslateSBML.mexmaci, OutputSBML.mexmaci and CheckAndConvert.m will have been installed as /usr/local/lib/TranslateSBML.mexmaci, /usr/local/lib/OutpuSBML.mexmaci and /usr/local/lib/CheckAndConvert.m. You will need to set your DYLD_LIBRARY_PATH environment variable to /usr/local/lib, and also execute the following command (or an equivalent) in MATLAB:

addpath('/usr/local/lib');

To save the trouble of having to type the command above each time you start MATLAB, you may wish to put it in your startup.m file (i.e., the file MATLAB uses for user initialization). Please refer to the MATLAB documentation for more information about startup.m and where it is located.

MATLAB on Windows systems

Most Windows users will probably prefer to install libSBML using the self-extracting installer provided separately and available for downloading from the same servers as the libSBML source code distribution. The installer will take care of placing the MATLAB files in directories where MATLAB can find them. Nothing further needs to be done in that case. You should be able to start MATLAB at will, and be able to invoke functions like TranslateSBML and OutputSBML.

If you are compiling and installing libSBML from the sources, or else want/need to install the MATLAB bindings directly from the libSBML source distribution on Windows, follow these simple steps:

  1. Start MATLAB.
  2. Within MATLAB, change directory to the directory in your libSBML source tree containing the MATLAB code. This directory will be libsbml/src/bindings/matlab, where libsbml is the root of your libSBML source directory on your computer.
  3. Execute buildSBML in MATLAB.
  4. Execute installSBML in MATLAB.

After these steps, you should be able to invoke functions such as TranslateSBML and OutputSBML. These will be accessible after you restart MATLAB and even when you are no longer in the libSBML directory.