From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id A209DBC37 for ; Tue, 29 Dec 2009 17:10:06 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjABAKe4OUsmachmmWdsb2JhbACbTwEBAQEBCAsKBxO6GoQzBA X-IronPort-AV: E=Sophos;i="4.47,469,1257116400"; d="scan'208";a="39484755" Received: from mx2.janestcapital.com ([38.105.200.102]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 29 Dec 2009 17:10:04 +0100 Received: from nyc-qsv-mail1.delacy.com ([172.25.22.57]) by mx2.janestcapital.com with esmtp (Exim 4.69) (envelope-from ) id 1NPee2-0000lF-Sa; Tue, 29 Dec 2009 11:10:02 -0500 Received: from nyc-qsv-004.delacy.com ([172.25.22.194] helo=qsmtp.delacy.com) by nyc-qsv-mail1.delacy.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1NPee2-0001CX-Ru; Tue, 29 Dec 2009 11:10:02 -0500 Received: from lon-qws-r01.delacy.com ([172.30.3.51] helo=lon-qws-r01) by qsmtp.delacy.com with smtp (Exim 4.63) (envelope-from ) id 1NPee0-00005a-VT; Tue, 29 Dec 2009 11:10:02 -0500 Received: by lon-qws-r01 (sSMTP sendmail emulation); Tue, 29 Dec 2009 16:10:00 +0000 From: "Mark Shinwell" Date: Tue, 29 Dec 2009 16:10:00 +0000 To: lin hong Cc: caml-list@inria.fr Subject: Re: [Caml-list] How to add a "non-standard" static c library to ocaml project Message-ID: <20091229161000.GP23955@janestreet.com> References: <56473.216.73.250.141.1262102149.squirrel@webmail.amnh.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56473.216.73.250.141.1262102149.squirrel@webmail.amnh.org> User-Agent: Mutt/1.5.18 (2008-05-17) X-Spam: no; 0.00; shinwell:01 non-standard:01 ocaml:01 cflags:01 foo:01 foo:01 -static:01 2009:98 continually:98 wrote:01 caml-list:01 unresolved:02 output:02 linking:02 linking:02 On Tue, Dec 29, 2009 at 10:55:49AM -0500, lin hong wrote: > I'm struggling with this for few days. > > We have a static C library, instead of "libsomename.a", it's "somename.a", > so we could not link it in the usually way like "-lsomename". > In myocamlbuild.ml, I did try to add it's head files dir into cflags, and > "/somelib/dir/somename.a" to clibs. This works for Mac, however, in Linux, > it won't pass the linking process. I suspect this is because the order of arguments on the linker command line is wrong. I think it is the case that when using the GNU linker, and object file foo.o has unresolved symbols that are to be found in static library bar.a, that you have to specify foo.o on the command line before bar.a. (This means you may have to specify a static library multiple times.) However it looks like Mac OS X is different. Reading the manual page for ld on Mac OS X says: "Unlike traditional linkers, ld will continually search a static library while linking. There is no need to specify a static library multiple times on the command line." which is maybe why your link is working on the Mac -- even if you haven't specified the .a multiple times, perhaps it is going back and re-examining the static library when it encounters the object later on the command line. You shouldn't have to specify the full path to the static library; at least on a system using the GNU linker you should be able to use something like: -static -lsomename -dynamic in the middle of the command. Just as a side point, an output of the linker errors pasted into an email is always useful for this sort of diagnosis. Hope that helps, Mark