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

2

7

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}

Ryter answered 10/3, 2019 at 10:9 Comment(5)
The contents of hello.lisp are irrelevant, it's complaining that c:build-program doesn't exist.Tier
Try c::build-program in case it's not exported for some reason.Tier
@Tier Running c::build-program just gets me a similar error Condition of type: UNDEFINED-FUNCTION The function C::BUILD-PROGRAM is undefined. Available restarts: 1. (RESTART-TOPLEVEL) Go back to Top-Level REPL. Broken at SI:BYTECODES. [Evaluation of: (C::BUILD-PROGRAM "CompiledFile" "hello.lisp")] In: #<process TOP-LEVEL>.Ryter
I'm not sure what's going on. All the ECL documentation says that this function should be there. Are you sure you're using ECL and not some other CL implementation?Tier
@Tier yep, using installed prebuilt from common-lisp.net/project/ecl/static/files/prebuiltRyter
T
6

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.

Tier answered 10/3, 2019 at 11:51 Comment(3)
That definitely seems to be the right direction but I encountered a strange issue when using it, > (require 'cmp) ;;; Loading #P"C:/Program Files (x86)/ECL/cmp.fas" Condition of type: SIMPLE-ERROR LOAD: Could not load file #P"C:/Program Files (x86)/ECL/cmp.fas" (Error: "The operation completed successfully. ") Available restarts: 1. (RESTART-TOPLEVEL) Go back to Top-Level REPL. Broken at SI:BYTECODES. [Evaluation of: (REQUIRE 'CMP)] In: #<process TOP-LEVEL>. and then I received the same errors when trying again. (cmp.fas is in the directory)Ryter
Sorry, don't know what to tell you. I don't have Windows so I can't try it myself.Tier
All good, at least I've made some progress towards fixing it. Thanks for the help!Ryter
A
4

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"))
Afra answered 30/4, 2021 at 19:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.