Building a Stand-alone Executable

Since the output of mzc relies on MzScheme to provide all run-time support, there is no way to use mzc to obtain small stand-alone executables. However, it is possible to produce a large stand-alone executable that contains an embedded copy of the MzScheme (or MrEd) run-time engine.

5.1  Stand-Alone Executables from Scheme Code

The command-line flag --exe directs mzc to embed a module (from source or byte code) into a copy of the MzScheme executable. The created executable invokes the embedded module on startup. The --gui-exe flag is similar, but copies the MrEd executable.

If the embedded module refers statically (i.e., through require) to modules in MzLib or other collections, then those modules are also included in the embedding executable.

Library modules that are referenced dynamically -- through eval, load, or dynamic-require -- are not automatically embedded into the created executable, but they can be explicitly included using mzc's --lib flag.

The --exe and --gui-exe flags work only with module-based programs. The embed.ss library in the compiler collection provides a more general interface to the embedding mechanism.

5.2  Stand-Alone Executables from Native Code

Creating a stand-alone executable that embeds native code from mzc requires downloading the MzScheme source code and using a C compiler and linker directly.

To build an executable with an embedded MzScheme engine:

For example, under Unix, to create a standalone executable MyApp that is equivalent to

mzscheme -mv -f file1.ss -f file2.ss

unpack the MzScheme source code and perform the following steps:

cd plt/src/mzscheme
./mzmake
./mzmake ee-main
mzc --object --embedded file1.ss
mzc --object --embedded file2.ss
mzc --link-glue --embedded file1.kp file1.o file2.kp file2.o
./mzmake EEAPP=MyApp EEOBJECTS="file1.o file2.o _loader.o" ee-app

To produce an executable that embeds the MrEd engine, the procedure is essentially the same; MrEd's main file is mrmain.cxx instead of main.c. See the compilation notes in the MrEd source code distribution for more information.