[gambit-list] How to create small standalone executable with Gambit-C?
Marc Feeley
feeley at iro.umontreal.ca
Mon Aug 17 17:11:20 EDT 2009
On 17-Aug-09, at 1:30 AM, peter lo wrote:
> Dear all,
> I am new to Gambit-C. I keep hearing that with Gambit-C, it is
> easy to create small executable. But when I tried, a simple hello
> world program takes around 3 MB when compiled as a STANDALONE
> executable. Is there a way to create small executable which includes
> only used functions, just like in C, we don't link the whole library
> into the executable.
>
> Thanks.
>
> Peter
It depends what you mean by a "standalone" executable. Do you include
the shared libraries in the program's size? Do you include the
operating system, which implements the low-level side of the libraries?
I assume you are interested in how much space is required on the file
system to store the executable. Here's a simple experiment on Mac OS
X of compiling a hello-world program in Scheme and C. Gambit is setup
to use shared libraries, which is fair since that's what the C
compiler normally does when it compiles and links a C program.
% cd gambc-v4_5_1-devel
% ./configure --enable-shared --enable-single-host --prefix=/Users/
feeley/g
% make
% make install
% cat hello-world.scm
(println "Hello World")
% ~/g/bin/gsc -exe hello-world.scm
% ./hello-world
Hello World
% otool -L hello-world
hello-world:
/Users/feeley/g/lib/libgambc.dylib (compatibility version 0.0.0,
current version 0.0.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current
version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
version 111.1.4)
% ls -l hello-world /Users/feeley/g/lib/libgambc.dylib /usr/lib/
libgcc_s.1.dylib /usr/lib/libSystem.B.dylib
-rw-r--r-- 1 feeley feeley 4316808 Aug 17 16:39 /Users/feeley/g/lib/
libgambc.dylib
-r-xr-xr-x 1 root wheel 7895472 Apr 1 01:45 /usr/lib/
libSystem.B.dylib
-rw-r--r-- 1 root wheel 264016 Oct 6 2007 /usr/lib/libgcc_s.
1.dylib
-rwxr-xr-x 1 feeley feeley 13124 Aug 17 16:47 hello-world
% gcc -shared hello-world.c
% otool -L a.out
a.out:
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current
version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
version 111.1.4)
% ls -l a.out /usr/lib/libgcc_s.1.dylib /usr/lib/libSystem.B.dylib
-r-xr-xr-x 1 root wheel 7895472 Apr 1 01:45 /usr/lib/
libSystem.B.dylib
-rw-r--r-- 1 root wheel 264016 Oct 6 2007 /usr/lib/libgcc_s.
1.dylib
-rwxr-xr-x 1 feeley feeley 12588 Aug 17 16:49 a.out
So the actual executables (hello-world and a.out) are almost the same
size on the file system. They both use some of the system's shared
libraries, in particular libSystem.B.dylib which is almost 8MB. The
Gambit program also links with Gambit's runtime library,
libgambc.dylib, which is 4MB. So even if you include the shared
libraries in the program's "size", both programs are reasonably
similar in size (8MB vs 12MB).
Marc
More information about the Gambit-list
mailing list