Subject: Re: CCL:How to call a C++ program from C?

From: [email-masked]
Date: Wed, 29 Sep 1999 16:53:00 +0200

> I have a big program which is written in C and Fortran, but mainly in C.
> The author compile each module by their own compiler ( cc and f77 on SGI) 
> and link them by f77.
> 
> Now I have another C++ program (still others) and want incorporate it 
> into the previous big program.

This is difficult, and certainly not possible in a portable way.

Mixing C and Fortran is easy, but you should use f77 to link (on
some systems this is not strictly necessary; adding the Fortran
libraries when linking is sufficient).

Mixing C and C++ is also easy, but you must use CC to link.

So for mixing C with C++ and Fortran, you'd have to link with both
CC and f77.

The reason for this problem is that both C++ and Fortran program often
need specific initialization code that is added during linking. An
added complication with C++ is name mangling (the compiler must create
unique names for overloaded functions etc.), but there are ways around
that.

In summary, what you are trying to do is possible only on a system
that allows calling Fortran from C without any special initialization
code for Fortran. I don't know whether this is true for SGI systems.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                            | E-Mail: [email-masked]
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.55.69
Rue Charles Sadron                       | Fax:  +33-2.38.63.15.17
45071 Orleans Cedex 2                    | Deutsch/Esperanto/English/
France                                   | Nederlands/Francais
-------------------------------------------------------------------------------