[gambit-list] Some notes on compiling gambit. (was: Using the tcc compiler)

Bradley Lucier lucier at math.purdue.edu
Fri Jul 27 23:17:57 EDT 2007


I started composing this before Marc replied, but still it may be of  
use.

The current instructions in the documentation for how to build a  
standalone executable are wrong; here are some new instructions for  
that and some comments on how to speed up compiles of scheme code (at  
the expense of some performance).  These notes aren't specifically  
directed at you, Christian, but I wrote them a week or so ago for  
another purpose, and they seem vaguely relevant to your request.

If there are several scheme and c files, follow the instructions on  
how to compile them from scheme to c and then use gsc -link to get  
the *_.c file.  Here we assume there is only one scheme file called  
all.scm.  Pretty much the easiest way to build a stand-alone  
executable is

> [brad:~/Desktop/gambit-anagram] lucier% gsc -link all.scm
> [brad:~/Desktop/gambit-anagram] lucier% gcc -I/usr/local/Gambit-C/ 
> current/include/ -D___SINGLE_HOST -fstrict-aliasing -fwrapv -O1 -c  
> all.c
> [brad:~/Desktop/gambit-anagram] lucier% gcc -I/usr/local/Gambit-C/ 
> current/include/ -D___SINGLE_HOST -fstrict-aliasing -fwrapv -O1 -c  
> all_.c
> [brad:~/Desktop/gambit-anagram] lucier% gcc -o all all.o all_.o -L/ 
> usr/local/Gambit-C/current/lib -lgambc -ldl -lm

Here I assume that gambit was installed in the usual place /usr/local/ 
Gambit-C/current; if this was changed using --prefix= in the  
configure command then change these.  You need -fstrict-aliasing and - 
fwrapv for correctness when compiling with gcc.  -O1 is a good  
default compilation option.  If you want to give up a bit more speed  
for possibly much faster compilation, then add the option - 
D___OPTIMIZE_SPACE.  Other ways to make the compilation go faster is  
to omit the -O1 and the -D___SINGLE_HOST, but I don't recommend this.

The library options "-lgambc -ldl -lm" change from system to system;  
sometimes they include "-lutil" and other libraries.

MARC:  THERE SHOULD BE COMMANDS CALLED SOMETHING LIKE "gambit- 
compile" AND "gambit-link" THAT (a) COMPILE .c FILES AND (b) LINKS  
THEM TOGETHER WITH THE CORRECT OPTIONS AND LIBRARIES.

MARC:  THERE SHOULD BE SOMETHING LIKE

./configure --simple-gcc-options

THAT JUST HAS THE FEW OPTIONS GIVEN ABOVE FOR GAMBIT.  Not everyone  
wants to spend the compile time, and several times now there have  
been cryptic comments on this mail list about how to get rid of the  
default gcc options, even without --enable-gcc-opts.

If you do

% gsc file.scm

to make a dynamically loadable file, then it's compiled using /usr/ 
local/Gambit-C/current/gsc-cc-o (in general, it's `which gsc-cc-o`).   
As Marc said, you can edit that file (copying the original somewhere  
else beforehand if you like) before compiling.  On my MacOS X  
machine, it's

> [brad:Arrays/srfi3/Binf-2] lucier% cat `which gsc-cc-o`
> #! /bin/sh
> GSC_CC_O_ARG1=$1
> shift
> GSC_CC_O_ARG2=$1
> shift
> GSC_CC_O_ARG3=$1
> shift
> gcc -mcpu=7450 -D___OPTIMIZE_SPACE  -no-cpp-precomp -Wall -W -Wno- 
> unused -O1 -fno-math-errno -fschedule-insns2 -fno-trapping-math - 
> fno-strict-aliasing -fwrapv -fexpensive-optimizations -fforce-addr - 
> fpeephole2 -falign-jumps -falign-functions -fno-function-cse -ftree- 
> copyrename -ftree-fre -ftree-dce -fregmove -fgcse-las -freorder- 
> functions -fcaller-saves -fno-if-conversion2 -foptimize-sibling- 
> calls -fcse-skip-blocks -funit-at-a-time -finline-functions -fomit- 
> frame-pointer -fPIC -fno-common -bundle -flat_namespace -undefined  
> suppress -I${GSC_CC_O_ARG1}include -D___DYNAMIC -D___SINGLE_HOST -o  
> ${GSC_CC_O_ARG2} $* ${GSC_CC_O_ARG3}

As you can see, I configured Gambit with

> env CC='gcc -mcpu=7450 -D___OPTIMIZE_SPACE' ./configure --enable- 
> single-host

The "-fwhatever" optimization options to gcc can be omitted except  
for the two I listed above.  So you can reduce the set of options to

> gcc -no-cpp-precomp -fno-strict-aliasing -fwrapv -fPIC -fno-common - 
> bundle -flat_namespace -undefined suppress -I${GSC_CC_O_ARG1} 
> include -D___DYNAMIC -o ${GSC_CC_O_ARG2} $* ${GSC_CC_O_ARG3}

You need another "-f" option for dynamically loaded libraries, "- 
fPIC".  You also need "-D___DYNAMIC" for dynamically loaded libraries.

I don't know what the other options are, but I know they aren't  
optimization options, and they change from system to system.  After  
you strip out the options you don't want then you can add back in  
what you may want, like

> gcc -O1 -D___OPTIMIZE_SPACE -no-cpp-precomp -fno-strict-aliasing - 
> fwrapv -fPIC -fno-common -bundle -flat_namespace -undefined  
> suppress -I${GSC_CC_O_ARG1}include -D___DYNAMIC -o ${GSC_CC_O_ARG2}  
> $* ${GSC_CC_O_ARG3}

which offers about the best trade-off for execution speed and compile  
time for slow machines (or rapid development).

Brad



More information about the Gambit-list mailing list