From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id EAA22735; Tue, 12 Jun 2001 04:19:31 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id EAA22451 for ; Tue, 12 Jun 2001 04:19:29 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f5C2JRD23662 for ; Tue, 12 Jun 2001 04:19:28 +0200 (MET DST) Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3/3.7W) with ESMTP id LAA22783; Tue, 12 Jun 2001 11:19:04 +0900 (JST) To: cartan@cartan.de Cc: caml-list@inria.fr Subject: Re: [Caml-list] How to link libraries with C parts (Bug?) In-Reply-To: References: X-Mailer: Mew version 1.94.2 on Emacs 20.7 / Mule 4.0 (HANANOEN) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20010612111904Y.garrigue@kurims.kyoto-u.ac.jp> Date: Tue, 12 Jun 2001 11:19:04 +0900 From: Jacques Garrigue X-Dispatcher: imput version 20000228(IM140) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: Nils Goesche > I have got a strange problem: I am writing an Ocaml library > which uses some C code. However, when I try to link this library to > an application, I get consistently some strange error (see below). I > guess I am building the library incorrectly, but I have tried a > gazillion of variations to no avail. [...] > That's it. Now I build it: > > $ ocamlc.opt -c mylib.mli > > $ ocamlopt.opt -c mylib.ml > > $ cc -c -DNATIVE_CODE -I /usr/local/lib/ocaml mylibcall.c -o mylibcall.o > > $ ocamlopt.opt -a mylibcall.o -o mylib.cmxa mylib.cmx In order to use the autolink feature of ocaml, you should put your C object inside a library. That is: $ ar cf libmylibcall.a mylibcall.o $ ocamlopt.opt -a -cclib -lmylibcall -o mylib.cmxa mylib.cmx Then the rest should work correctly > > Compiling it: > > $ ocamlopt.opt -c -I /home/nils/src/caml/bug/mylib myapp.ml > > And linking: > > $ ocamlopt.opt -I /home/nils/src/caml/bug/mylib \ > -ccopt -L/home/nils/src/caml/bug/mylib mylib.cmxa \ > -o myapp myapp.cmx You don't even need the -ccopt -L... : all directories marked by -I are automatically added in the link. Cheers, Jacques Garrigue ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr