我正在运行Ubuntu 18.04,并安装了来执行Scheme脚本。 可以正常工作,可以解释我提供的任何文件,REPL也按预期工作。不幸的是,我无法弄清楚如何使用。http://gambitscheme.org/wiki/index.php/A_Tour_of_Scheme_in_Gambit提供了很少关于如何使用编译程序的信息,更多地涉及并未涵盖所有可用选项(例如,在
根据http://www.iro.umontreal.ca/~gambit/doc/gambit.html的建议,使用
我到此为止,但我尝试过其他两个教程,都没有成功,而且我现在找不到它们了。
如果上述任何方法可以修改以适合我,或者如果有任何其他过程允许脚本编译成可执行文件(即使是简单的单文件程序),我将感激不尽。
man
页面中未提及选项-o
和-c
),而我能找到的所有其他来源都对我没有用。让我详细说明一下最后一部分:
使用Gambit制作可执行文件的第一个答案是针对Windows的。
尝试按照第二个答案所述操作会出现以下情况:
$ cat hello.scm
;#!/usr/local/bin/gsi-script -:d0
;
(define hello-world
(lambda ()
(begin (write `Hello-World) (newline) (hello-world))))
(define (main)
(hello-world))
那么
$ gsc hello.scm
$ ls
hello.o1 hello.scm
$ ./hello.o1
Segmentation fault (core dumped)
失败了,同样如此
$ gsc -c hello.scm
$ ls
hello.c hello.scm
$ gcc -o hello hello.c
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o : In function « _start » :
(.text+0x20) : Undefined reference to « main »
/tmp/ccnDUVi0.o : [30 more lines]
collect2: error: ld returned 1 exit status
- 进行中
/* File: "m1.c" */
int power_of_2 (int x) { return 1<<x; }
; File: "m2.scm"
(c-declare "extern int power_of_2 ();")
(define pow2 (c-lambda (int) int "power_of_2"))
(define (twice x) (cons x x))
; File: "m3.scm"
(write (map twice (map pow2 '(1 2 3 4)))) (newline)
$ gsc -c m2.scm # create m2.c (note: .scm is optional)
$ gsc -c m3.scm # create m3.c (note: .scm is optional)
$ gsc -link m2.c m3.c # create the incremental link file m3_.c
$ gsc -obj m1.c m2.c m3.c m3_.c
m1.c:
m2.c:
m3.c:
m3_.c:
$ gcc m1.o m2.o m3.o m3_.o -lgambit -lm -ldl -lutil
$ ./a.out
((2 . 2) (4 . 4) (8 . 8) (16 . 16))
根据http://www.iro.umontreal.ca/~gambit/doc/gambit.html的建议,使用
$ gsc -obj m1.c m2.c m3.c m3_.c
失败,提示m3_.c
未定义。即使忽略这一点,再次使用$ gcc m1.o m2.o m3.o m3_.o -lgambit -lm -ldl -lutil
时,它也抱怨-lgambit
未定义。但该文档确实解释了-o
和-c
选项的使用方法。我到此为止,但我尝试过其他两个教程,都没有成功,而且我现在找不到它们了。
如果上述任何方法可以修改以适合我,或者如果有任何其他过程允许脚本编译成可执行文件(即使是简单的单文件程序),我将感激不尽。
$ gsc -exe hello
命令,但终端返回了以下信息:hello_.o:(.data.rel+0x150) : référence indéfinie vers « ____20_hello » collect2: error: ld returned 1 exit status *** ERROR IN ##main -- C link failed while linking "/home/vanille/ALGO/Scheme/hello_.o"
- Neven V.hello
已经被编译时,.scm
是必需的。我得到了一个输出文件,现在需要找出为什么启动它没有任何反应。 - Neven V.gsc
等开关来解决问题,你应该检查为什么你系统上的链接器不起作用。 - rsm