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 VAA29636; Fri, 8 Jun 2001 21:46:39 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA29693 for ; Fri, 8 Jun 2001 21:46:38 +0200 (MET DST) Received: from moutvdom00.kundenserver.de (moutvdom00.kundenserver.de [195.20.224.149]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f58JkbL25407 for ; Fri, 8 Jun 2001 21:46:37 +0200 (MET DST) Received: from [195.20.224.204] (helo=mrvdom00.schlund.de) by moutvdom00.kundenserver.de with esmtp (Exim 2.12 #2) id 158SDN-0003CJ-00 for caml-list@inria.fr; Fri, 8 Jun 2001 21:46:37 +0200 Received: from [62.154.173.138] (helo=pc022.bln.elmeg.de) by mrvdom00.schlund.de with esmtp (Exim 2.12 #2) id 158SCM-0000MJ-00 for caml-list@inria.fr; Fri, 8 Jun 2001 21:45:34 +0200 To: caml-list@inria.fr Subject: [Caml-list] How to link libraries with C parts (Bug?) From: Nils Goesche Date: 08 Jun 2001 21:45:28 +0200 Message-ID: User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi! 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. Here a simple example: First, the library. Interface mylib.mli: val hello: unit -> string Implementation mylib.ml: external hello: unit -> string = "hello" Real implementation mylibcall.c: #include #include #include value hello(void) { static const char text[] = "hello"; static const int len = 5; CAMLparam0(); CAMLlocal1(ret); ret = alloc_string(len); strncpy(String_val(ret), text, len); CAMLreturn(ret); } 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 That's it, I leave all intermediate files where they are. Now for the application (sources in another directory): Source myapp.ml: let _ = print_endline (Mylib.hello ()) 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 gcc: mylibcall.o: No such file or directory Error during linking If I copy mylibcall.o into the directory with the application sources, everything workes fine. But I wouldn't want to ask any users of the library to copy that damned .o file into all their directories :-) What am I doing wrong? Because it seems to work for instance with the lablGL libraries I generated on this machine :-( Regards, -- Nils Goesche "Don't ask for whom the tolls." PGP key ID 0x42B32FC9 ------------------- 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