From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id C90BDBC69 for ; Sat, 24 Nov 2007 04:09:38 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAE4lR0dA6ba8kmdsb2JhbACPPQEBAQEHAgYp X-IronPort-AV: E=Sophos;i="4.21,459,1188770400"; d="scan'208";a="19625108" Received: from nf-out-0910.google.com ([64.233.182.188]) by mail4-smtp-sop.national.inria.fr with ESMTP; 24 Nov 2007 04:09:36 +0100 Received: by nf-out-0910.google.com with SMTP id e27so6964nfd for ; Fri, 23 Nov 2007 19:09:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:date:to:subject:message-id:references:mime-version:content-type:content-disposition:content-transfer-encoding:in-reply-to:user-agent:from; bh=LsOGS+50xOPN0FDyJj50XPmNdIUSu1TLY8DnWeGeTH8=; b=KGml7DLlOZwceHHwJ21iSjlMD1h2QeRgdoCLoEcEbTEN/SSTg6CTIk0sShtZkl/lTDuYz3MguEMuCB3dhOq3z5cWK5+kmZNrgAJUcYnJnYtikPVXYTT7gDldis+tyzzyuEaw+7MU1Bs8a2bFIVWngTtZ9/1liwtykr1UL6t38zI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=received:date:to:subject:message-id:references:mime-version:content-type:content-disposition:content-transfer-encoding:in-reply-to:user-agent:from; b=WvNfCL4VFjtbBCZeCYBz9KUrqlZmf7GK++1KLu69hgyUwvvn++qAwRgGyD3UbSfu8mFi+TDNmUUQbQ/3dBjVt0dKuNYPegXAAJCJO/Nngf0NfPrFa9/kP7EJFzglvEAr95D9h1KAHvMtgv12VXMbtqDZlcybEfyQfWS8gXsNpNM= Received: by 10.86.79.19 with SMTP id c19mr7791fgb.1195873775445; Fri, 23 Nov 2007 19:09:35 -0800 (PST) Received: from localhost ( [82.122.248.16]) by mx.google.com with ESMTPS id v23sm3990176fkd.2007.11.23.19.09.31 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 23 Nov 2007 19:09:33 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Sat, 24 Nov 2007 04:10:46 +0100 Date: Sat, 24 Nov 2007 04:10:46 +0100 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Re: Options order for ocamlc/opt/opt.opt Message-ID: <20071124031046.GA2581@localhost> References: <200711230243.34108.toots@rastageeks.org> <200711231740.27208.toots@rastageeks.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <200711231740.27208.toots@rastageeks.org> User-Agent: Mutt/1.5.17 (2007-11-01) From: Julien Moutinho X-Spam: no; 0.00; ocamlc:01 0100,:01 gentoo:01 gcc:01 -wl:01 gcc:01 -cclib:01 clflags:01 ccobjs:01 foo:01 flags:01 printf:01 sprintf:01 clflags:01 ccomp:01 On Fri, Nov 23, 2007 at 05:40:27PM +0100, Romain Beauxis wrote: > Le Friday 23 November 2007 02:43:34, vous avez =C3=A9crit=C2=A0: > > The fix in this case is to simply fix the linking order so that the > > libraries given to the linker are all after the object files and the st= atic > > archives." > (...) > > There's a good documentation where the above statement is taken there: > > =C2=A0 http://www.gentoo.org/proj/en/qa/asneeded.xml > > > > What do you think ? >=20 > Well, I'm quite confused with this... >=20 > After spending some time finding out how to change those arguments order,= =20 > I ended up with a patch that orders them just perfectly,=20 > so that the following is passed: >=20 > gcc <-I options> -Wl,--as-needed -o object >=20 > This is exactly what's refered as a good practice in the above link, but = still I got my linking wrong... >=20 > Ha, and of course this option works on a simple hello_world with the same= gcc... Options passed to -cclib are in !Clflags.ccobjs to which -l flags are = appended, hence your patch: Printf.sprintf "%s %s %s %s %s %s %s %s %s %s -o %s" !Clflags.c_linker (if !Clflags.gprofile then Config.cc_profile else "") (Clflags.std_include_flag "-I") (Ccomp.quote_files (List.map (fun dir -> if dir =3D "" then "" else "-L" ^ dir) !load_path)) (String.concat " " !Clflags.ccopts) (Ccomp.quote_files (List.rev !Clflags.ccobjs)) (Filename.quote startup_file) (Ccomp.quote_files (List.rev file_list)) (Ccomp.quote_optfile runtime_lib) c_lib (Filename.quote output_name) gives (it can easily be seen by wrapping /usr/bin/gcc with a shell script /usr/local/bin/gcc echoing its arguments): gcc -I/usr/local/lib/ocaml -L/usr/local/lib/ocaml /tmp/camlstartupf0fb45.= o \ /usr/local/lib/ocaml/std_exit.o test.o /usr/local/lib/ocaml/stdlib.a \ /usr/local/lib/ocaml/libasmrun.a -Wl,--as-needed -lm -ldl -o test Which is not what you want, isn't it. But now, what exactly is wrong for you in: ocamlopt -o test -ccopt '-Wl,--as-needed' -cclib '-lunix' test.ml which gives (with a vanilla release310 branch): gcc -o test -I/usr/local/lib/ocaml -Wl,--as-needed \ /tmp/camlstartupd18cfa.o /usr/local/lib/ocaml/std_exit.o test.o \ /usr/local/lib/ocaml/stdlib.a -L/usr/local/lib/ocaml -lunix \ /usr/local/lib/ocaml/libasmrun.a -lm -ldl HTH, Julien.