从SLIME运行时无法找到软件包,但是从命令行可以 [英] not able to find package when running from SLIME, but from command line is ok
问题描述
我正在运行茶壶示例, cl-opengl软件包.我所做的唯一更改就是加载了所需的程序包.从unix shell(sbcl --load "3.cl"
)执行时,它可以正常工作,但是当我尝试通过SLIME(C-c C-k
)进行编译和加载时,却遇到未找到有关包GLUT
的错误.
I'm running the teapot example from cl-opengl package. The only changes I've made are loading the required packages. It works fine when executed from unix shell (sbcl --load "3.cl"
), but when I try to compile and load it through SLIME (C-c C-k
) i get the error about package GLUT
not found.
奇怪的是,编译器对(defclass glut-teapot-window (glut:window)
感到窒息.
会带来什么?
Curiously, the compiler chokes on the (defclass glut-teapot-window (glut:window)
.
What gives???
这是3.cl的代码.
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;; glut-teapot.lisp --- Simple usage of glut:solid-teapot.
(ql:quickload :cl-opengl)
(ql:quickload :cl-glu)
(ql:quickload :cl-glut)
;(setf *communication-style* :fd-handler)
(defclass glut-teapot-window (glut:window)
()
(:default-initargs :width 250 :height 250 :title "glut-teapot.lisp"
:mode '(:single :rgb :depth)))
(defmethod glut:display-window :before ((w glut-teapot-window))
(gl:clear-color 0 0 0 0)
(gl:cull-face :back)
(gl:depth-func :less)
(gl:disable :dither)
(gl:shade-model :smooth)
(gl:light-model :light-model-local-viewer 1)
(gl:color-material :front :ambient-and-diffuse)
(gl:enable :light0 :light1 :lighting :cull-face :depth-test))
(defmethod glut:display ((window glut-teapot-window))
(gl:load-identity)
(gl:translate 0 0 -5)
(gl:rotate 30 1 1 0)
(gl:light :light0 :position '(100 1000 1 0))
(gl:light :light0 :diffuse '(1.2 0.4 0.6 0))
(gl:light :light1 :position '(-100 1000 1 0))
(gl:clear :color-buffer :depth-buffer)
(gl:color 1 10 1)
(gl:front-face :cw)
(glut:solid-teapot 1.3)
;(glut:solid-torus 0.5 1.0 50 50)
;(glu:cylinder (glu:new-quadric) 0.5 0.5 0.5 20 20)
(gl:front-face :ccw)
(gl:flush))
(defmethod glut:reshape ((window glut-teapot-window) width height)
(gl:viewport 0 0 width height)
(gl:matrix-mode :projection)
(gl:load-identity)
(glu:perspective 50 (/ width height) 0.5 20)
(gl:matrix-mode :modelview)
(gl:load-identity))
(defmethod glut:keyboard ((window glut-teapot-window) key x y)
(declare (ignore x y))
(when (eql key #\Esc)
(glut:destroy-current-window)))
(defun glut-teapot ()
(glut:display-window (make-instance 'glut-teapot-window)))
(glut-teapot)
推荐答案
如果加载文件,则Lisp系统将按表达式读取文件表达式,并在读取每个表达式后执行它们.
If you load the file, the Lisp system reads the file expression by expression and executes them after reading each single expression.
如果在新的Lisp中编译文件,则它将读取表达式并进行编译.但是它不会执行它们.因此,它看到quickload命令,对其进行编译,但不执行它.此OpenGL代码未加载,并且编译器不知道软件包.但这是有道理的:编译通常应该编译文件,而不是执行文件.当您加载编译的fasl文件时,Lisp会执行这些表达式.
If you compile the file in a fresh Lisp, then it reads the expressions and compiles them. But it does not execute them. Thus it sees the quickload command, compiles it, but does not execute it. This OpenGL code is not loaded and the packages are not known to the compiler. But that makes sense: a compile usually should compile the file, not execute it. Lisp would execute the expressions then when you load the compiled fasl file.
有两种简单的解决方法:
There are two simple ways around it:
- 将quickload操作放入一个单独的文件中,然后在编译下一个文件之前对其进行编译/执行.
- 将装入操作括在
EVAL-WHEN
语句中.(eval-when (:execute :load-toplevel :compile-toplevel) ... your code here ...)
.
- put the quickload operation in a separate file and compile/execute it before compiling the next file.
- enclose the load operations in an
EVAL-WHEN
statement.(eval-when (:execute :load-toplevel :compile-toplevel) ... your code here ...)
.
:compile-toplevel
符号表示,当编译器将其视为顶级形式时,将执行该代码.否则它不会这样做.因此,您可以在文件中包含要编译的代码,这会产生副作用-在这里加载其他代码.
The :compile-toplevel
symbol means, that the code will be executed when the compiler sees it as a top-level form. Which it otherwise would not do. Thus you can have code in a file to compile which creates side effects - here loading other code.
这篇关于从SLIME运行时无法找到软件包,但是从命令行可以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!