[gambit-list] Distributing Gambit Source/compiled C code
Marc Feeley
feeley at iro.umontreal.ca
Wed May 21 15:33:41 EDT 2008
On 20-May-08, at 12:35 PM, Joel J. Adamson wrote:
> Dear List,
>
> I have a small game project that I'd like to distribute to a wider
> audience (i.e., people who don't have Gambit-C). I've gotten it to
> compile fully on my system, but I'd like to make sure someone else can
> compile it. If I distribute Gambit-compiled C, what do I need to
> include (gambit.h, _gambc.c?) so that anyone with a C compiler can
> compile it?
>
> I know this would be simple for me to figure out if I knew more
> about C;
> I throw myself humbly at your broadly educated feet.
You need:
lib/*.c
lib/*.h
include/*.h
and the .c files generated by the Gambit-C compiler for your Scheme
source code.
The executable program can then be built with:
% gcc -DHAVE_CONFIG_H -fno-strict-aliasing *.c -o myprogram.exe
You can add a mix of the following C compiler options to optimize the
program:
-O1
-D___SINGLE_HOST
-fomit-frame-pointer
Here's a complete example (commands executed from Gambit's root
directory):
% mkdir myprog
% mkdir myprog/lib
% mkdir myprog/include
% mkdir myprog/src
% cd myprog
% cp ../lib/*.c lib
% cp ../lib/*.h lib
% cp ../include/*.h include
% cd src
% cat > foo.scm
(display "hello\n")
% cat > bar.scm
(display "world\n")
% gsc -link foo.scm bar.scm
% gcc -I../lib -I../include -DHAVE_CONFIG_H -fno-strict-aliasing ../
lib/*.c *.c -o myprogram.exe
../lib/mem.c:1492:32: warning: trigraph ??> ignored, use -trigraphs to
enable
% ./myprogram.exe
hello
world
Note that the header files in Gambit's include directory (i.e.
gambit.h and config.h) are generated by Gambit's configure script to
match the features of your build platform. If you want a highly
portable distribution of your program you should use a similar
configure script. Basically, take a copy of configure.ac from the
Gambit distribution and change the line
AC_OUTPUT(makefile include/makefile include/gambit.h ...)
to
AC_OUTPUT(include/gambit.h)
Then do
% autoconf configure.ac > configure
% chmod 755 configure
And put include/gambit.h.in and include/config.h.in in your include
directory.
The build procedure for your program will then be:
% ./configure
% gcc -Ilib -Iinclude -DHAVE_CONFIG_H -fno-strict-aliasing lib/*.c
*.c -o myprogram.exe
Its also a good idea to use makefiles instead of a single call to gcc.
Alternatively, you could distribute your program with Gambit's .tar.gz
and build Gambit before building your program. This has the added
benefit that you can supply the .scm files and the end-user can change
them and rebuild the program.
Marc
More information about the Gambit-list
mailing list