[gambit-list] multiple main functions!

Ryan Prescott ryan at xlgames.com
Fri Jul 21 11:06:58 EDT 2006


I've gotten rid of the multiple main issue.

I actually removed ALL my code from the file, compiled the resulting
files, built my app and I still got the exception when ___setup() was
called. My termite process did not work properly afterward. This code
works properly when I test it using the interpereter.

Hopefully there aren't any scheme newbie errors here.
If I use the following code, I see the hello? and backend starting
statements, but nothing else. I added more display calls to make sure
everything was happening as expected and as far as I can tell,
everything's okay.

; back-node is initted via (define back-node (make-node ..))
; spawn-register spawns a termite process and registers it's pid
;  with the termite nameserver

(display "hello?\n")

(define backend
   (let ((listeners '()))
     (display "backend starting\n")
     (node-init back-node)
     (spawn-register
       (lambda ()
         (let loop ((listeners listeners))
           (display "backend entering recv\n")
           (pp listeners)
           (recv
             ((from tag ('RegisterListener msg))
              (begin
                (display "regstered listener")
                (loop (cons msg listeners))))
             (after 10
                    (begin
                      (display "i'm alive")
                      (loop (ping-listeners listeners)))))
           (loop listeners)))
       'backend)))

Many thanks,

Ryan


Marc Feeley wrote:
 > Ryan, you need to link to libgambc.a (which does not have a main
 > function).  The best way to see how this can be done is to build the
 > pthread example (i.e. cd examples/pthread; make examples).  The pthread
 > example has a main function in C, and several C threads that call into
 > Scheme (one at a time thanks to a POSIX threads mutex).  You should also
 > look at test #8 (i.e. cd tests; make test8).  It has a C main function
 > that calls into Scheme to evaluate some S-expressions in strings.
 >
 > Hope that answers your question.
 >
 > Marc
 >
 > On 20-Jul-06, at 6:21 PM, Ryan Prescott wrote:
 >
 >> Hi,
 >>
 >> I've perused the archives of the Gambit-C mailing list looking for info
 >> on this issue so I apologize if this is a well known issue.
 >>
 >> I've got a C application that I want to use a gambit thread
 >> (actually a termite process). I have a main function defined in C and
 >> a library defined in scheme that I want to init/call from C.
 >>
 >> Unfortunately, I get multiple main functions when building and the msvc
 >> linker doesn't like that too much. Being brave, I instructed the linker
 >> to ignore the multiple main error condition and "just use" my C main
 >> func.
 >>
 >> This does NOT seem to result in a stable situation for the scheme world,
 >> as when I call __setup() I get an exception. Note that the exception is
 >> handled by the gambit runtime, but there definitely seems to
 >> be some init time badness. The termite process does not respond to
 >> messages, etc.
 >>
 >> I also tried defining ___LIBRARY during C builds to no avail. This did
 >> get rid of the multiple main error, but I still get the exception.
 >>
 >> Is there any way to get gambit to not generate a main function? I guess
 >> I was looking for something like chicken's -embedded option. I had some
 >> amount of hope when perusing gambit.h at the -flat option, but I think
 >> this requires me to resolve functions at startup manually.
 >>
 >> (chicken doc reference http://galinha.ucpel.tche.br/Embedding)
 >>
 >> FYI I'm building the scheme code with:
 >>     gsc -f -check myfile.scm
 >>
 >> Thanks,
 >> Ryan
 >>
 >> _______________________________________________
 >> Gambit-list mailing list
 >> Gambit-list at iro.umontreal.ca
 >> http://mailman.iro.umontreal.ca/mailman/listinfo/gambit-list
 >



More information about the Gambit-list mailing list