4 Creating a DLL

4.1 Compiling the C++ program

The Mozart system provides oztool which we recommend you invoke instead of calling the C/C++ compiler directly:

oztool c++ -c getenv.cc -o getenv.o

oztool takes care of many unpleasant details for you; for example, it supplies the compiler with the appropriate option for the generation of position independent code.

4.2 Creating a dynamic library

Now, we create a shared object from the compiled object file obtained above. Again you should invoke oztool rather than call the linker directly:

oztool ld getenv.o -o getenv.so

This takes care of many ugly details (especially on Windows where they could easily drive you nuts). Actually, you should really create a shared object file with, as suffix, the platform for which it was created. For example:

oztool ld getenv.o -o getenv.so-linux-i486

The reason is that the Oz module manager was designed to support platform independent module import specifications, but, of course, native modules must be resolved to platform dependent implementations. The default resolution strategy achieves this by means of platform suffixes.

In order to write portable makefiles, you can use oztool to print out the platform name:

oztool platform

Thus a portable way to create the shared object is:

oztool ld getenv.o -o getenv.so-`oztool platform`


Michael Mehl, Tobias Müller, Christian Schulte and Ralf Scheidhauer
Version 1.4.0 (20080702)