[previous] [up] [next]     [contents] [index]
Next: Index Up: PLT mzc: MzScheme Compiler Previous: Macro and Elaboration-Time Libraries

Building a Stand-alone Native Code Executable

Since native code produced by mzc relies on MzScheme to provide all run-time support, there is no way to use mzc to obtain small stand-alone native code executables. However, the source code to MzScheme is available, so it is possible to produce a large stand-alone executable that contains an embedded copy of the MzScheme run-time engine. This process requires using a C compiler and linker directly.

To build an executable with an embedded MzScheme engine, first download the source code and compile MzScheme (see http://www.cs.rice.edu/CS/PLT/packages/mzscheme). Then, recompile MzScheme's main.c with the preprocessor symbol STANDALONE_WITH_EMBEDDED_EXTENSION defined. The preprocessor symbol causes the startup code skip command line parsing, the user's initialization file, and the read-eval-print loop. Instead, the C function scheme_initialize is called, which will be the entry point into mzc-compiled Scheme code. After compiling with STANDALONE_WITH_EMBEDDED_EXTENSION defined, MzScheme will not link by itself; it must be linked with objects produced by mzc.

Compile each Scheme source file in the program with mzc's -o or --object flag and the --embedded flag, producing a set of .kp files and object (.o or .obj) files. After each Scheme file is compiled, run mzc with the -g or --glue-extension and the --embedded flag, providing all of the .kp files and object files on the command line. (Put the object files in the order that they should be ``loaded.'') The -g or --glue-extension step produces one last object file: _loader.o or _loader.obj.

Finally, link all of the mzc-created object files with the MzScheme implementation (having compiled main.c with STANDALONE_WITH_EMBEDDED_EXTENSION defined) to produce a stand-alone executable.

Each of the Scheme source files in the program must have a different base name, otherwise _loader will confuse them, but they do not have to be in the same directory. Once the stand-alone executable is created, all .kp and object files can be deleted.


[previous] [up] [next]     [contents] [index]
Next: Index Up: PLT mzc: MzScheme Compiler Previous: Macro and Elaboration-Time Libraries

PLT