What is the correct way to compile a file using Embeddable Common Lisp?

1.6k Views Asked by At

I attempting to use ECL to create a .o file with the intention of using its feature of compiling to C however I am receiving an error when trying to build a program as the documentation lists.

I am running:

(c:build-program "CompiledFile" "hello.lisp")

An receiving the error:

Debugger received error of type: SIMPLE-ERROR
Cannot find the external symbol BUILD-PROGRAM in #<"C" package>.
Error flushed.
>> "CompiledFile"
>> "hello.lisp"
>> ;;; Warning: Ignoring an unmatched right parenthesis.

The contents of hello.lisp are as follows:

(defun say-hello ()
  (print "Hello, world"))

(say-hello)
(terpri)
(quit)

I am following the documentation found here https://common-lisp.net/project/ecl/static/manual/ch34s03.html and it has the function definition as:

c:build-program {image-name &key lisp-files ld-flags prologue-code epilogue-code}

2

There are 2 best solutions below

3
Barmar On BEST ANSWER

According to https://ecls-list.narkive.com/xACoJUbf/c-build-program-and-eval the compiler isn't loaded by default, you need to use

(require 'cmp)

first.

I'm not sure why this isn't mentioned in the manual.

0
Lucas Barbosa On

According to ECL manual, you need to initialize C/C++ compiler to generate the .o files:

(ext:install-c-compiler)
(compile-file "hello.lisp" :system-p t) ; Now this produces .o file

To generate an executable from .o:

(c:build-program "CompiledFile" :lisp-files '("hello.o"))