How To Use Shared Libraries

Stratego -- Strategies for Program Transformation
From StrategoXT 0.11 the Stratego Runtime creates libraries using Libtool. This means that both static and shared libraries are constructed (on platforms that support shared libraries). In general, linkers prefer shared libraries over static libraries, thus Stratego programs will be linked with shared libraries.

This introduces the usual advantages and disadvantages of shared libraries. For example, an advantage is that executables are smaller and the code of the runtime is shared. The main disadvantage is that the libraries need the be found when the executable is invoked. This is a common problem for all packages that are using shared libraries.

Some methods to avoid the disadvantages are:

  • Use Libtool for linking in your package that uses StrategoXT. Libtool will add the directories of dynamic libraries to the search path of the executables. This solves the problem of run-time lookup of a shared library that is not installed in a default directory for libraries at your system. To use Libtool in your package, just add AC_PROG_LIBTOOL to your configure.in (or configure.ac).

  • If programs are not linked in this way, then the user can set the LD_LIBRARY_PATH to include the location of the Stratego runtime libraries in the StrategoXT installation.

  • If you just hate dynamic libraries, then you can configure StrategoXT with the standard Libtool option --disable-shared: ./configure ... --disable-shared. This will only construct static libraries. All your programs (also in your own packages) will now use static linking, since there no shared libraries available.

  • If your StrategoXT installation contains shared libraries, but you don't want the programs in your package to use them, then you can enforce static linking by passing the -static option to the configure of your package: LDFLAGS: ./configure ... LDFLAGS=-static.