[comp.lang.c++] Portability of compiled libraries

jbuck@janus.Berkeley.EDU (Joe Buck) (05/02/91)

In article <1991May1.112346.13948@fmrco> harold@fmrco (Harold Naparst) writes:
>
>To what extent can a library compiled with compiler A be used
>by a program compiled with compiler B ?
>
>My question concerns the uniqueness of the name mangling scheme.

No, it doesn't.  That is, name mangling is the least of your problems.
You also need for both compilers to implement virtual functions in the
same way; otherwise, virtual function calls using classes defined in
the library won't work right.  g++ and cfront differ in how they do
virtual functions; the g++ scheme never does more than two pointer
dereferences and the cfront scheme is often less efficient.

In general, there are tricks that can be played by compilers that go
directly to assembly language that can't be used by compilers that go
to C (trivial example: use a specified register to contain the "this"
pointer), and it's unreasonable to expect the writers of such compilers
to give up competitive advantages to be compatible with cfront.

--
Joe Buck
jbuck@janus.berkeley.edu	 {uunet,ucbvax}!janus.berkeley.edu!jbuck	

gjditchfield@watmsg.waterloo.edu (Glen Ditchfield) (05/03/91)

In article <1991May1.112346.13948@fmrco> harold@fmrco (Harold Naparst) writes:
>To what extent can a library compiled with compiler A be used
>by a program compiled with compiler B ?
>My question concerns the uniqueness of the name mangling scheme.

In article <42018@ucbvax.BERKELEY.EDU> jbuck@janus.Berkeley.EDU (Joe Buck) writes:
>... name mangling is the least of your problems.  You also need for both
>compilers to implement virtual functions in the same way...  In general,
>there are tricks that can be played by compilers that go directly to
>assembly language that can't be used by compilers that go to C (trivial
>example: use a specified register to contain the "this" pointer), and it's
>unreasonable to expect the writers of such compilers to give up
>competitive advantages to be compatible with cfront.

The string literal in a linkage specification is usually though of as a
language name, but it can just as easily be a compiler name.  So, the GNU
people could solve this problem* by providing a "cfront" linkage.
    extern "cfront" {
        // Interface for library compiled by AT&T C++
    }

--------
* ... if they have time on their hands, and if AT&T has documented the
  interface to cfront-compiled code.  Neither seems likely.

    Glen Ditchfield  gjditchfield@violet.uwaterloo.ca  Office: DC 2517
Dept. of Computer Science, U of Waterloo, Waterloo, Ontario, Canada, N2L 3G1
	      These opinions have not been tested on animals.