[Ecls-list] Handling C/C++ pointers in lisp code (Was "can't compile with g++")

Larry Clapp larry at theclapp.org
Tue Mar 2 21:36:00 UTC 2004

On Mon, Mar 01, 2004 at 03:38:51PM +0100, Juan Jose Garcia-Ripoll wrote:
> > Okay.  Recompile using -with-cxx and -with-ffi.  Will do.
> If anything fails, please report it.

Well, it turns out that even with "extern "C" { ... }" around it,
clos_ensure_class() still causes problems for g++.  I reconfigured
with --with-cxx, and all that.  Results:

- first, C:*CC* still defaults to "gcc".  No big deal (and I couldn't
  actually find anything in the docs that implied that it would
  magically switch to "g++"), and easily fixed anyway:
    (let ((c:*cc* "g++")) 
	(compile-file #| ... |#))

  All hail dynamic binding.  :)

- second, I bound C:*CC* to "g++" as above, and recompiled, and it
  generated this in my .h file:

    #ifdef __cplusplus
    extern "C" {
    // ...
    extern cl_object clos_ensure_class();
    // ...
    #ifdef __cplusplus

g++ still reports

    too many arguments to function `cl_lispunion* clos_ensure_class()'

I pasted the g++ command sequence into my command line, and got the
same error (surprise).  I added "-D__cplusplus" just to make sure, and
got the same error.  I deleted the "#ifdef __cplusplus" stuff out of
the .h file, leaving the "extern "C" { ... }" stuff (just to make
*really* sure :), and got the same error.

I changed the .h file to say:

    // ...
    extern cl_object clos_ensure_class(
    #ifdef __cplusplus
    // ...

and that worked.  I found where ecl emits the extern line, and patched

--- 8< cut here ---
--- cmpcall.lsp.orig     Thu Dec 11 12:17:01 2003
+++ cmpcall.lsp	Tue Mar  2 23:48:50 2004
@@ -220,7 +220,11 @@
        ;; We only write declarations for functions which are not
        ;; in lisp_external.h
        (when (and (not found) (not (si::mangle-name fname t)))
-         (wt-h "extern cl_object " fd "();")
+         (wt-h "extern cl_object " fd "(
+#ifdef __cplusplus
+    ...
          (setf (gethash fd *compiler-declared-globals*) 1)))
        (if (minusp maxarg)
--- >8 cut here ---

and that made it work automatically, at least for my tiny test case.
We'll see if it works for longer code, and other functions.

-- Larry

More information about the ecl-devel mailing list