2008-08-24 10 views
57

Je viens de commencer à apprendre Lisp et je n'arrive pas à comprendre comment compiler et lier du code Lisp à un exécutable.Lisp Executable

J'utilise clisp et clisp -c produit deux fichiers:

  • .fas
  • .lib

Que dois-je faire pour obtenir un exécutable?

+0

Vous pouvez utiliser 'compile-file' à la place. –

Répondre

47

je suis en train d'essayer de le faire aujourd'hui, et je trouve taper ceci dans le Clisp REPL travaillé:

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

où principale est le nom de la fonction que vous voulez appeler lorsque le programme lance, :QUIET t supprime la bannière de démarrage, et :EXECUTABLE t rend un exécutable natif.

Il peut également être utile d'appeler

(EXT:EXIT) 

à la fin de votre fonction principale afin d'empêcher l'utilisateur d'obtenir une invite de Lisp interactif lorsque le programme est fait. EDIT: En lisant la documentation, vous pouvez également ajouter :NORC t (lire link). Cela supprime le chargement du fichier RC (par exemple, ~/.clisprc.lisp).

+0

Sur ccl sur mac os x 10.9 j'ai un problème pour exécuter des executables. '(application-save"/full/chemin/vers/save-app ": prepend-kernel t)' double-cliquer sur le fichier exécutable produit entre sur le terminal affichant de très longues erreurs commençant par une erreur similaire: problèmes loading bundle: Impossible de déterminer le nom de la classe et de terminer avec les options du débogueur du noyau. Sur ccl windows je définis simplement une fonction et fais la même chose ci-dessus pour sauvegarder l'exécutable, plus tard je peux double cliquer sur le fichier de sortie qu'il exécute et mémoriser ma fonction définie, ccl sur mac ne me souviens pas aussi quand je sauvegarde l'image –

35

Ceci est un Lisp FAQ (légèrement adapté):

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

Pour un moyen portable pour ce faire, je vous recommande roswell.

Pour toute implémentation prise en charge, vous pouvez créer des scripts Lisp pour exécuter le programme qui peut être exécuté de manière portable par ros qui peut être utilisé dans une ligne de hachage similaire à un programme python ou ruby.

Pour SBCL et CCL, Roswell peut également créer des exécutables binaires avec ros dump executable.

+0

Pourquoi cela a-t-il été réduit? – Thayne

0

;; Je sais que c'est une vieille question, mais le code Lisp je regarde est de 25 ans :-)

Je ne pouvais pas travailler avec la compilation clisp sur Windows 10. Cependant, il a travaillé pour moi avec GCL

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

;; mon fichier lisp est jugs2.lisp

gcl -compile jugs2.lisp ;; ceci produit le fichier jugs2.o si jugs2.le fichier lisp n'a aucune erreur

;; exécuter gcl sans paramètre pour lancer l'interpréteur lisp gcl

;; charger le fichier .o

(load "jugs2.o")

;; créer un exe

(si:save-system "jugs2")

;; lorsque l'exe est exécuté, il a besoin de la DLL oncrpc.dll ;; C'est dans le dossier \ lib \ gcl-2.6.1 \ unixport que gcl.bat crée.

;; lorsqu'il est lancé, il affiche un environnement lisp, appel (principal) pour exécuter la fonction principale (principal)