[comp.sys.mac.programmer] Allegro CL <-> MPW C/C++

cearl@aristotle.ils.nwu.edu (Charles Earl) (12/20/89)

I am trying to call a C++ program written in MPW C++ v3.1 from Allegro Common 
Lisp. The test C++ program simply computes the factorial of the integer
argument. 

I compile the C++ program succesfully, load the Lisp FF.fasl file, and load
the C++ object with the following call to ff-load

(ff-load "CPlusExamples;simple.cp.o"
         :entry-names '("fac")
         :ffenv-name 'test
         :libraries '("CPlusExamples;SimpleLib.o"))

where "fac" is the name of the factorial routine, "simple.cp.o" is the object,
and SimpleLib.o, created with the MPW Lib routine, contains the objects that
simple.cp needs to link to.

When this command is evaled, Allegro reports: "Unknown Object File version (2)
in #<Object #174, "hd:mpw:examples:CPlusExamples:simple.cp.o", a 
CCL::*FILE-STREAM*>". Further, when deffcfun is evaluated 
("(deffcfun (factorial "fac") (fixnum) :long)") ACL reports that there is no
"fac" entry point.

Have I grossly missed somehthing, or is the version 1.2.2 of ACL I have 
incompatable with C++ insofar as the foreign function interface is concerned?

Comments, theories welcomed.

CEarl

joemac@Apple.COM (Joe MacDougald) (12/20/89)

One problem is that C++ encrypts (mangles) the function entry point to include
information about scope and parameter type (type-safe linking).

You need to define external entries to the library with:

extern "C" {
	int foo();
	int bar();
	// ...
}

This tells cfront not to encrypt those entries (they have C linkage).

As far as the Object file format not being recognized, well, I can't tell you
much about that.

--joe

chewy@apple.com (Paul Snively) (12/20/89)

In article <5870@internal.Apple.COM> joemac@Apple.COM (Joe MacDougald) 
writes:
> As far as the Object file format not being recognized, well, I can't 
tell you
> much about that.

But I can.  You are using MPW 3.0 or later, which produces a new version 
of the .o files, which the FFI for Allegro 1.2.2 doesn't recognize.  With 
Joe's information, you should be able to ignore the warning, and when 
Allegro 1.3 ships I'd recommend upgrading--1.3 recognizes MPW 3 .o files 
and has a lot of nice new features as well.

__________________________________________________________________________
Just because I work for Apple Computer, Inc. doesn't mean that they 
believe what I believe or vice-versa.
__________________________________________________________________________
C++ -- The language in which only friends can access your private members.
__________________________________________________________________________