caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Julien Moutinho <julien.moutinho@gmail.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Re: Options order for ocamlc/opt/opt.opt
Date: Sat, 24 Nov 2007 04:10:46 +0100	[thread overview]
Message-ID: <20071124031046.GA2581@localhost> (raw)
In-Reply-To: <200711231740.27208.toots@rastageeks.org>

On Fri, Nov 23, 2007 at 05:40:27PM +0100, Romain Beauxis wrote:
> Le Friday 23 November 2007 02:43:34, vous avez écrit :
> > 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 static
> > archives."
> (...)
> > There's a good documentation where the above statement is taken there:
> >   http://www.gentoo.org/proj/en/qa/asneeded.xml
> >
> > What do you think ?
> 
> Well, I'm quite confused with this...
> 
> After spending some time finding out how to change those arguments order, 
> I ended up with a patch that orders them just perfectly, 
> so that the following is passed:
> 
>   gcc <other options> <-I options> -Wl,--as-needed <base_file.o> <project_files.o> <static_libraries.a> <dynamic list of -lfoo> -o object
> 
> This is exactly what's refered as a good practice in the above link, but still I got my linking wrong...
> 
> 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<foo> 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 = "" 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.


  reply	other threads:[~2007-11-24  3:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-23  1:43 Romain Beauxis
2007-11-23 16:40 ` Romain Beauxis
2007-11-24  3:10   ` Julien Moutinho [this message]
2007-11-24  3:15     ` [Caml-list] " Julien Moutinho
2007-12-02 21:39       ` Romain Beauxis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071124031046.GA2581@localhost \
    --to=julien.moutinho@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).