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}

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
Dan Harmon
  • 313
  • 1
  • 13
  • The contents of `hello.lisp` are irrelevant, it's complaining that `c:build-program` doesn't exist. – Barmar Mar 10 '19 at 11:15
  • Try `c::build-program` in case it's not exported for some reason. – Barmar Mar 10 '19 at 11:17
  • @Barmar 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: #.` – Dan Harmon Mar 10 '19 at 11:22
  • 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? – Barmar Mar 10 '19 at 11:31
  • @Barmar yep, using installed prebuilt from https://common-lisp.net/project/ecl/static/files/prebuilt/ – Dan Harmon Mar 10 '19 at 11:38

2 Answers2

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.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 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: #.` and then I received the same errors when trying again. (cmp.fas is in the directory) – Dan Harmon Mar 10 '19 at 11:56
  • 1
    Sorry, don't know what to tell you. I don't have Windows so I can't try it myself. – Barmar Mar 10 '19 at 12:01
  • All good, at least I've made some progress towards fixing it. Thanks for the help! – Dan Harmon Mar 10 '19 at 12:02
1

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"))
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61