In C/C++, I can make a library, and make it static one or dll using #include "" in source code, and -labc when linking. How do I have the same feature in lisp?
As an example of util.lisp in directory A. I define a library function hello.
(defpackage "UTIL" (:use "COMMON-LISP") (:nicknames "UT") (:export "HELLO")) (in-package util) (defun hello () (format t "hello, world"))
And try to use this library function from main function.
(defun main () (ut:hello)) (main)
I tried
clisp main.lisp A/util.lisp
But, I got the following message
*** - READ from #: there is no package with name "UT"
I just had to load the library.
(load "./A/util.lisp") (defun main () (ut:hello)) (main)
And run 'clisp main.lisp' works fine.
You have to load util.lisp before main.lisp:
> (load "util.lisp")
> (load "main.lisp")
> (main)
hello, world
NIL
Practical Common Lisp has a good introduction to defining and using packages.