我刚刚开始学习Lisp,我不知道如何编译Lisp代码并将其链接到可执行文件。
我正在使用clisp和clisp -c生成两个文件:
接下来我该怎么做才能获得可执行文件?
我实际上今天正在尝试执行此操作,但发现在CLisp REPL中键入以下内容有效:
1 2 3 4 5
| (EXT:SAVEINITMEM"executable.exe"
:QUIET t
:INIT-FUNCTION 'main
:EXECUTABLE t
:NORC t) |
其中main是您要在程序启动时调用的函数的名称,:QUIET t禁止显示启动标语,而:EXECUTABLE t则使本机可执行文件。
打电话也很有用
在您的主要功能的末尾,以阻止用户在程序完成后获得交互式Lisp提示。
编辑:阅读文档,您可能还想添加:NORC t
(阅读链接)。这样可以禁止加载RC文件(例如,~/.clisprc.lisp)。
这是一个Lisp常见问题解答(略有改动):
*** How do I make an executable from my programme?
This depends on your implementation; you will need to consult your
vendor's documentation.
-
With ECL and GCL, the standard compilation process will
produce a native executable.
-
With LispWorks, see the Delivery User's Guide section of the
documentation.
-
With Allegro Common Lisp, see the Delivery section of the
manual.
-
etc...
However, the classical way of interacting with Common Lisp programs
does not involve standalone executables. Let's consider this during
two phases of the development process: programming and delivery.
Programming phase: Common Lisp development has more of an
incremental feel than is common in batch-oriented languages, where an
edit-compile-link cycle is common. A CL developer will run simple
tests and transient interactions with the environment at the
REPL (or Read-Eval-Print-Loop, also known as the
listener). Source code is saved in files, and the build/load
dependencies between source files are recorded in a system-description
facility such as ASDF (which plays a similar role to make in
edit-compile-link systems). The system-description facility provides
commands for building a system (and only recompiling files whose
dependencies have changed since the last build), and for loading a
system into memory.
Most Common Lisp implementations also provide a"save-world" mechanism
that makes it possible to save a snapshot of the current lisp image,
in a form which can later be restarted. A Common Lisp environment
generally consists of a relatively small executable runtime, and a
larger image file that contains the state of the lisp world. A common
use of this facility is to dump a customized image containing all the
build tools and libraries that are used on a given project, in order
to reduce startup time. For instance, this facility is available under
the name EXT:SAVE-LISP in CMUCL, SB-EXT:SAVE-LISP-AND-DIE in
SBCL, EXT:SAVEINITMEM in CLISP, and CCL:SAVE-APPLICATION in
OpenMCL. Most of these implementations can prepend the runtime to the
image, thereby making it executable.
Application delivery: rather than generating a single executable
file for an application, Lisp developers generally save an image
containing their application, and deliver it to clients together with
the runtime and possibly a shell-script wrapper that invokes the
runtime with the application image. On Windows platforms this can be
hidden from the user by using a click-o-matic InstallShield type tool.
CLiki也有一个很好的答案:创建可执行文件
看看官方的剪辑首页。有一个常见问题解答可以回答这个问题。
http://clisp.cons.org/impnotes/faq.html#faq-exec
对于便携式方法,我建议罗斯威尔。
对于任何受支持的实现,您都可以创建lisp脚本来运行可以由ros以可移植方式运行的程序,该程序可以在哈希爆炸行中使用,类似于python或ruby程序。
对于SBCL和CCL,roswell还可以使用ros dump executable创建二进制可执行文件。
我知道这是一个老问题,但是我正在查看的Lisp代码已有25年的历史了:-)
我无法在Windows 10上使用clisp进行编译。
但是,它与gcl对我有用。
如果我的Lisp文件是jugs2.lisp,
如果jugs2.lisp文件没有错误,则生成文件jugs2.o。
运行不带参数的gcl以启动lisp解释器:
加载.o文件:
要创建一个EXE:
当EXE运行时,它需要DLL oncrpc.dll。这是在gcl.bat创建的\lib\gcl-2.6.1\unixport文件夹中。
运行时显示一个Lisp环境,调用(main)运行main函数
(主要)。