small solved problem linking caml with Fortran

From: Basile STARYNKEVITCH (basile.starynkevitch@cea.fr)
Date: Thu Mar 05 1998 - 09:54:51 MET


Date: Thu, 5 Mar 1998 09:54:51 +0100
Message-Id: <199803050854.JAA04199@orion.serma.cea.fr>
From: Basile STARYNKEVITCH <basile.starynkevitch@cea.fr>
To: caml-list@inria.fr
Subject: small solved problem linking caml with Fortran

This is mainly for ocaml developers but perhaps some users might have
an insight.

Caml (ocaml-1.07 bytecode compiler &interpreter) is used here as an
embedding langage for numerical applications programmed in Fortran.

Plateform is a Linux/Intel Pentium II. Kernel is 2.0.33, distribution
is (patched) Redhat-5.0, libc is libc-2.0.6.so, binutils is 2.8.1.0.1
(not .0.15!), egcs-1.0.1 compiler suite (including f77 & libf2c)

The problem is that both fortran's /usr/lib/libf2c.a and caml's
/usr/local/lib/ocaml/libcamlrun.a defines a main function (in amain.o
member)

The custom top level is built with

ocamlmktop -custom -o toplevel fthebase.cmo fthebasec.o F*.o -cclib /usr/lib/libf2c.a

fthebasec.o is built from fthebasec.c. it is a C wrapper calling
fortran routines and prividing ocaml C custom primitives

fthebase.cmo is customer's Caml code

F*.o is built from fortran77 F*.f sources

The problem is that ocaml first links in the provided
(Fortran's) /usr/lib/libf2c.a and then the caml's
/usr/local/lib/ocaml/libcamlrun.a

So Fortran's main.o is being loaded, and caml's main.o is not loaded.

The solving hack is to

extract the main.o from /usr/local/lib/ocaml/libcamlrun.a and rename
it as camlmain.o

build the top level with
ocamlmktop -custom -o toplevel camlmain.o fthebase.cmo fthebasec.o F*.o -cclib /usr/lib/libf2c.a

My suggestion is either to document it in the manual, or better to
explicitly provide in /usr/local/lib/ocaml/ the camlmain.o object
file.

I also believe that the caml's /usr/local/lib/libcamlrun.a should be
linked by ocaml before additional -cclib-ed libraries.

I also would like an undocumented -dkeep option which would keep all
temporary files that ocaml creates (gcc has a similar flag
-save-temps). Having such an option would satisfy my curiosity :-) and
probably help debug such problems.

Thanks for all.

N.B. Any opinions expressed here are solely mine, and not of my organization.
N.B. Les opinions exprimees ici me sont personnelles et n engagent pas le CEA.

----------------------------------------------------------------------
Basile STARYNKEVITCH ---- Commissariat Ó l Energie Atomique
DRN/DMT/SYSCO * CEA/Saclay bat.460 * 91191 GIF/YVETTE CEDEX * France
fax: (33) 01,69.08.96.96; phone: 01,69.08.40.66; home: 01,46.65.45.53
email: Basile . Starynkevitch @ cea . fr (but remove white space)
I speak french, english, russian. Je parle franšais, anglais, russe.
----------------------------------------------------------------------



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:13 MET