Hi,
Found an example of calling Scheme functions from C but cannot compile it https://gist.github.com/ncweinhold/991905
% gsc -c somescheme.scm % gsc -link somescheme.c % gsc -obj somescheme.c main.c somescheme_.c % gcc somescheme.o somescheme_.o main.o -I$GAMBIT/include $GAMBIT/lib/libgambit.a -lm -ldl -lutil -lssl -lcrypto
ld: error: duplicate symbol: main
defined at somescheme_.c somescheme_.o:(main) defined at main.c main.o:(.text+0x0)
collect2: error: ld returned 1 exit status
How to prevent the main function generation in somescheme_.c ?
Many thanks for any help.
-Sonny
Afficher les réponses par date
By default the link file (here somescheme_.c generated from somescheme.c) contains a C “main” function so that without any additional step the code can be compiled and linked (at the C level) to obtain an executable program. In other words the entry point of the program will be the Gambit runtime system.
However your file main.c also defines a C “main” function so you end up with a duplicate definition. The way around this, shown below, is to compile the link file with the -D___LIBRARY C compiler option. This will cause the somescheme_.c file to avoid the inclusion of a C “main” function (through a series of #ifdefs). In other words, the Scheme code and the Gambit runtime system are acting as a library to the main C program.
Marc
gsc -c somescheme.scm gsc -link somescheme.c gsc -obj -cc-options -D___LIBRARY somescheme.c somescheme_.c <========= need the -cc-options here gsc -obj main.c gcc somescheme.o somescheme_.o main.o -I$GAMBIT/include $GAMBIT/lib/libgambit.a -lm -ldl -lutil -lssl -lcrypto
On Jul 12, 2021, at 3:57 PM, Sonny To son.c.to@gmail.com wrote:
Hi,
Found an example of calling Scheme functions from C but cannot compile it https://gist.github.com/ncweinhold/991905
% gsc -c somescheme.scm % gsc -link somescheme.c % gsc -obj somescheme.c main.c somescheme_.c % gcc somescheme.o somescheme_.o main.o -I$GAMBIT/include $GAMBIT/lib/libgambit.a -lm -ldl -lutil -lssl -lcrypto
ld: error: duplicate symbol: main
defined at somescheme_.c somescheme_.o:(main) defined at main.c main.o:(.text+0x0)
collect2: error: ld returned 1 exit status
How to prevent the main function generation in somescheme_.c ?
Many thanks for any help.
-Sonny
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://mailman.iro.umontreal.ca/cgi-bin/mailman/listinfo/gambit-list