2008-08-24 21 views
57

Tôi vừa mới bắt đầu học Lisp và tôi không thể tìm ra cách biên dịch và liên kết mã lisp với một tệp thực thi.Lisp Executable

Tôi đang sử dụng clispclisp -c sản xuất hai tập tin:

  • .fas
  • lib

gì Tôi phải làm tiếp theo để có được một thực thi?

+0

Bạn có thể sử dụng 'biên dịch tập tin' để thay thế. –

Trả lời

47

tôi đã thực sự cố gắng để làm ngày hôm nay, và tôi thấy gõ này vào CLISP REPL làm việc:

(EXT:SAVEINITMEM "executable.exe" 
       :QUIET t 
       :INIT-FUNCTION 'main 
       :EXECUTABLE t 
       :NORC t) 

nơi chính là tên của hàm bạn muốn gọi khi khởi chạy chương trình, :QUIET t chặn biểu ngữ khởi động và :EXECUTABLE t làm cho tệp thực thi gốc.

Nó cũng có thể hữu ích để gọi

(EXT:EXIT) 

vào cuối Chức năng chính của bạn để ngăn chặn người dùng từ nhận được một dấu nhắc lisp tương tác khi chương trình được thực hiện.

EDIT: Đọc tài liệu, bạn cũng có thể muốn thêm :NORC t (đọc link). Điều này ngăn chặn tải tập tin RC (ví dụ, ~/.clisprc.lisp).

+0

Trên ccl trên mac os x 10.9 tôi đang gặp sự cố khi thực thi cretaing. '(lưu-ứng dụng"/full/path/to/saved-app ": prepend-kernel t)' nhấp đúp vào tệp thi hành được tạo ra trên thiết bị đầu cuối hiển thị các lỗi rất dài bắt đầu bằng một lỗi như: lỗi loadiing bundle: không thể xác định tên lớp và kết thúc bằng các tùy chọn trình gỡ lỗi hạt nhân. Trên ccl trên windows tôi chỉ cần định nghĩa một hàm và thực hiện tương tự ở trên để lưu file thực thi, sau đó tôi có thể nhấp đúp vào tập tin đầu ra nó chạy và nhớ chức năng được xác định của tôi, ccl trên mac không nhớ nữa khi tôi lưu hình ảnh và tải nó vào kernel bằng tay –

35

Đây là một Lisp FAQ (hơi thích nghi):

*** 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.

3

Đối với một cách cầm tay để làm điều này, tôi khuyên bạn nên roswell.

Đối với bất kỳ triển khai được hỗ trợ nào, bạn có thể tạo tập lệnh lisp để chạy chương trình có thể chạy theo cách di động bằng ros có thể được sử dụng trong dòng băm ngang tương tự để nói chương trình python hoặc ruby.

Đối với SBCL và CCL roswell cũng có thể tạo tệp thực thi nhị phân với ros dump executable.

+0

Tại sao điều này lại được bình chọn? – Thayne

0

;; Tôi biết đây là một câu hỏi cũ nhưng mã Lisp Tôi nhìn vào là 25 tuổi :-)

tôi không thể có được biên soạn làm việc với CLISP trên Windows 10 Tuy nhiên, nó làm việc cho tôi với GCL

https://www.cs.utexas.edu/users/novak/gclwin.html

;; tệp lisp của tôi là jugs2.lisp

gcl -compile jugs2.lisp ;; điều này tạo ra tệp jugs2.o nếu jugs2.tệp lisp không có lỗi

;; chạy gcl không có tham số để khởi chạy trình thông dịch lisp gcl

;; tải tệp .o

(load "jugs2.o")

;; tạo một exe

(si:save-system "jugs2")

;; khi exe chạy nó cần dll oncrpc.dll ;; điều này nằm trong thư mục \ lib \ gcl-2.6.1 \ unixport mà gcl.bat tạo ra.

;; khi chạy nó cho thấy một môi trường lisp, gọi (chính) để chạy các chức năng chính (chính)