Static linking and standalone executables
One of the most frequent-asked feature for Gauche is the ability to compile a Scheme program and produce an executable file. Well, it finally comes in the upcoming 0.9.6 release!
Already in the repo, the build process creates a static library of
libgauche by default. There's also a script
build-standalone that takes Scheme script source files and spits a stand-alone binary executable---meaning, you can copy the single file to another machine and just run it, without having Gauche runtime there, given that the other machine is the same architecture. (Note: It statically links
libgauche but still depends on quasi-standard dynamic libraries such as
The detailed explanation is in the "Building standalone executables" section of the manual. There's a sample source in
examples/standalone you can play with.
If you just want to use the feature, that's all you need to know. The following is the discussion behind the scene...
＊ ＊ ＊
The ability to produce standalone executable is somewhat considered a distinguishing feature of programming language implementation that separates itself from interpreters or scripting languages.
However, we'd say such a feature has nothing to do with the language being interpreted or scripted. It is purely for the convenience of distributing Gauche programs.
In fact, what
build-standalone does is to take Scheme source files and generates a C code snippet with the Scheme code embedded as a C string literal, which is just
evaled when the binary is run. There's no performance advantage in the binary form. The static version of
libgauche also contains all of library code written in Scheme as C string literals, to be
evaled on demand.
In fact, it is a trade-off; a standalone binary is easier to distribute, but you lose flexibility of scripting that the user can easily modify the source and run immediately. Also, the size of stand-alone binaries is not small (16MB on Linux x86_64), because it carries around entire Gauche runtime in it. (It's Lisp's curse---because of
eval, we can't statically pick only required code.)
To distribute Gauche applications as Scheme scripts, you need Gauche runtime installed on the target machines. But that's the same for most languages---you need Java runtime to run Java applications, or even need
libc to run C applications. If you deploy a bunch of Gauche applications in a limited number of users, it might still be better to install Gauche runtime on each target machine and distribute Scheme files, rather than build a standalone binary for each of applications.
That said, the standalone executable feature will expand the use of Gauche, I hope.
(And I do plan to improve ahead-of-time compilation, employing more optimizations, so standalone binary may have performance advantage in some day.)