[previous] [up] [next]     [contents] [index]
Next: Compiling Collections with mzc Up: Compiling Individual Files with Previous: Autodetecting Compiled Files for

Compiling Multiple Files to a Single Native Code Library

When the -o or --object flag is provided to mzc, .kp and .o or .obj files are produced instead of a loadable library. The .o or .obj files contain the native code for a single source file. The .kp files contain information used for global optimizations.

Multiple .kp and .o or .obj files are linked into a single library using mzc with the -l or --link-extension flag. All of the .kp and .o or .obj files to be linked together are provided on the command line to mzc. The output library is always named _loader.so or _loader.dll.

For example:

  mzc --object file1.ss 
  mzc --object file2.ss 
  mzc --link-extension file1.kp file1.o file2.kp file2.o  
Under Unix, the above commands produce a _loader.so library that encapsulates both file1.ss and file2.ss.

Loading _loader into MzScheme is not quite the same as loading all of the Source files that are encapsulated by _loader. The return value from (load-extension "_loader.so") is a procedure that takes a symbol or #t. If a symbol is provided and it is the same as the base name of a source file (i.e., the name without a path or file extension) encapsulated by _loader, then a thunk is returned. Applying this thunk has the same effect as loading the corresponding source file. If a symbol is not recognized by the _loader procedure, #f is returned instead of a thunk. If #t is provided, a thunk is returned that ``loads'' all of the files (using the order of the .o or .obj files provided to mzc) and returns the result from loading the last one.

The _loader procedure can be called any number of times to obtain thunks, and each thunk can be applied any number of times (and each application has the same effect as loading the source file again). Evaluating (load-extension "_loader.so") multiple times returns an equivalent loader procedure each time.

Given the _loader.so constructed by the example commands above, the following Scheme expressions have the same effect as loading file1.ss and file2.ss:

  (((load-extension "_loader.so") 'file1))
  (((load-extension "_loader.so") 'file2)) 
or, equivalently:
  (((load-extension "_loader.so") #t)) 

The special _loader convention is recognized by MzScheme's load/use-compiled, load-relative, and require-library procedures. MzScheme automatically detects _loader.so or _loader.dll in the same directory as individual native code files (see section 2.2). If both an individual native code file and a _loader are available, the _loader file is used.


[previous] [up] [next]     [contents] [index]
Next: Compiling Collections with mzc Up: Compiling Individual Files with Previous: Autodetecting Compiled Files for

PLT