[gambit-list] cmake for projects written in gambit?

Matthew Koichi Grimes mkg at cs.nyu.edu
Tue Apr 5 19:07:27 EDT 2011


I've gotten Marc's "simple-make-project" example working, and now I'm trying
to adapt it to my own needs. The first of those needs is that I'd like to
have the "main" function be in Scheme rather than C.

I've written a minimal example featuring 3 files: main.scm,
hello_scheme.scm, and hello_c.c. The main.scm file calls two "hello world"
functions: a 'hello from Scheme!" function defined in hello_scheme.scm, and
a "hello from C!" function defined in hello_c.c.

I've changed "simple-make-project"'s makefile in just two ways: I've edited
the source filenames, and because the main function is now in Scheme rather
than C, I've changed

CC_OPTIONS = -D___LIBRARY

 to

CC_OPTIONS =

When I run "make", all my source files successfully compile to .o files, but
the link command that should link the .o files together into an executable
silently fails to produce anything. That final command is:

gsc -cc-options "" -ld-options "" -verbose -exe -o prog main.o
hello_scheme.o hello_c.o prog_.o

It neither produces the "prog" executable, nor does it even show what gcc
commands it called, despite use of the -verbose flag. It just silently
returns.

I've attached the project as a zip file. Any suggestions would be greatly
appreciated.

-- Matt

On Tue, Nov 30, 2010 at 6:18 PM, Marc Feeley <feeley at iro.umontreal.ca>wrote:

>
> On 2010-11-30, at 1:56 AM, Matthew Koichi Grimes wrote:
>
> > Has anybody used CMake as a build system for their Gambit projects? I'm
> not talking about building Gambit itself, but rather building projects that
> are written in Gambit. If so, could I see your CMakeList bulid files?
> >
> > I would also be interested in other build systems' makefiles (make, ant,
> etc), if people are wiling to share, or point me to an open-source project
> written in Gambit that I could download.
> >
> > Best,
> > -- Matt
>
> The attached tar ball shows how to write a makefile for a simple project
> built
> with Gambit-C which combines Scheme and C code.
>
> The C "main" function starts the execution of the Scheme code and it
> also contains a call to a Scheme procedure.  There are also calls to C
> functions within the Scheme code.  The project is composed of the
> following source files:
>
>  main.c              : program's "main" function which calls Scheme
>  mod1.h and mod1.c   : defines the mod1 C function
>  mod2.h and mod2.c   : defines the mod2 C function
>  mod3.h and mod3.scm : defines the interface between Scheme and C
>  mod4.scm            : Scheme code which calls C
>
> The makefile is designed to depend only on the gsc compiler.  The gsc
> compiler will invoke the appropriate C compiler and linker, even for
> compiling the C source files of the project.  This makes this makefile
> very portable as many system dependencies have been taken care of when
> Gambit was installed.
>
> To try it out, make sure you have Gambit-C v4.6.0 with
> commit 02c1427d40eb080a4ada916d55ecbb14cc191772.
>
> To build the project enter:
>
>  make
>
> To build and run the project enter:
>
>  make run
>
> To cleanup enter:
>
>  make clean
>
> The makefile and tar ball are below.
>
> Marc
>
>
> # Simple makefile for project built with Gambit-C system.
>
> # Copyright (c) 2010 by Marc Feeley, All Rights Reserved.
>
> # This makefile is designed to depend only on the gsc compiler.  The
> # gsc compiler will invoke the appropriate C compiler and linker, even
> # for compiling the C source files of the project.  This makes this
> # makefile very portable as many system dependencies have been taken
> # care of when Gambit was installed.  If gsc isn't installed in a
> # standard location, define GSC accordingly here:
>
> GSC = gsc
>
> # You should redefine C_MODULES and SCHEME_MODULES as needed for your
> # project.  Define ALL_MODULES_O as the set of object files for the C
> # and Scheme modules.  Define PROG_NAME as the program name.
>
> PROG_NAME = prog
> C_MODULES = mod1.c mod2.c main.c
> SCHEME_MODULES = mod3.scm mod4.scm
> SCHEME_MODULES_C = mod3.c mod4.c
> ALL_MODULES_O = mod1.o mod2.o main.o mod3.o mod4.o
>
> # You may want to add stuff to CC_OPTIONS and LD_OPTIONS (directories
> # for header files, libraries, etc).  You must keep -D___LIBRARY in
> # CC_OPTIONS so that the compiled Scheme code does not implement its
> # own "main" function (in the link file generated by gsc).
>
> CC_OPTIONS = -D___LIBRARY
> LD_OPTIONS =
>
> # The rest of the makefile shouldn't need to be modified.
>
> GSC_OPTIONS = -cc-options "$(CC_OPTIONS)" -ld-options "$(LD_OPTIONS)"
> #GSC_OPTIONS = -cc-options "$(CC_OPTIONS)" -ld-options "$(LD_OPTIONS)"
> -verbose
> ALL_MODULES_C = $(C_MODULES) $(SCHEME_MODULES_C)
> ALL_MODULES = $(C_MODULES) $(SCHEME_MODULES)
>
> .SUFFIXES:
> .SUFFIXES: .scm .c .o
>
> all: $(PROG_NAME)
>
> $(PROG_NAME): $(ALL_MODULES_O) $(PROG_NAME)_.o
>        $(GSC) $(GSC_OPTIONS) -exe -o $@ $^
>
> $(PROG_NAME)_.c:  $(SCHEME_MODULES_C)
>        $(GSC) -link -o $@ $^
>
> .c.o:
>        $(GSC) $(GSC_OPTIONS) -obj $^
>
> .scm.c:
>        $(GSC) $(GSC_OPTIONS) -c $^
>
> run: $(PROG_NAME)
>        ./$(PROG_NAME)
>
> clean:
>        rm -f $(SCHEME_MODULES_C) $(ALL_MODULES_O) $(PROG_NAME)_.*
> $(PROG_NAME)
>
>
> # Note: It is possible to compile and link a program in a single
> # invocation of gsc but this is not recommended for large projects
> # which usually benefit from separate compilation.  The command is:
> #
> #   $(GSC) $(GSC_OPTIONS) -exe -o $(PROG_NAME) $(ALL_MODULES)
> #
> # Moreover, this requires changing the name of the link file in main.c
> # from prog_.c to mod4_.c (the name is derived from the last Scheme
> # source file in ALL_MODULES).
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20110405/9c8689b5/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: simple.zip
Type: application/zip
Size: 2370 bytes
Desc: not available
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20110405/9c8689b5/attachment.zip>


More information about the Gambit-list mailing list