Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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}

like image 430
Dan Harmon Avatar asked Mar 10 '19 10:03

Dan Harmon


2 Answers

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.

like image 144
Barmar Avatar answered Nov 05 '22 06:11

Barmar


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"))
like image 32
Lucas Barbosa Avatar answered Nov 05 '22 05:11

Lucas Barbosa