English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Options order for ocamlc/opt/opt.opt
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-11-23 (01:43)
From: Romain Beauxis <toots@r...>
Subject: Options order for ocamlc/opt/opt.opt
	Hi all !

While trying to limit linking to non-needed libraries, I tried to use 
gcc's -Wl,--as-needed option.

Documentation states:
"This option affects ELF DT_NEEDED tags for dynamic libraries mentioned on the 
command line after the --as-needed option. Normally, the linker will add a 
DT_NEEDED tag for each dynamic library mentioned on the command line, 
regardless of whether the library is actually needed. --as-needed causes 
DT_NEEDED tags to only be emitted for libraries that satisfy some symbol 
reference from regular objects which is undefined at the point that the 
library was linked. --no-as-needed restores the default behaviour."

(-Wl means pass the option from gcc to the linker..)

So, as said, this option should be place *before* -l options..

However, when trying to use -cclib with this value, I get:
   '-lthreadsnat' '-lunix' '-lpthread' '-lunix' '-Wl,--as-needed'
which doesn't help...

Also, in order to work, one has also to take care or argument type order in 
gcc call:
'Basically, what the linker does is look for the symbols missing in a given 
file (either an object file, a static archive or a library) only in the files 
coming after it. When using the normal linking, without --as-needed, this is 
not a problem, although there might be some internal drawbacks on the linking 
stage, the files are linked together without considering ordering. But with 
the flag, the libraries that aren't used for resolving symbols are discarded 
and thus not linked.

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."

This is not either the case since I have:
  '-lthreadsnat' '-lunix' '-lpthread' '-lunix' '-Wl,--as-needed' 'float_pcm_c.o' 'oss_io_c.o' '/usr/lib/ocaml/3.10.0/libasmrun.a' -lm  -ldl

This also explains why forcing it on top of the list of arguments via -ccopt 
doesn't help either...

There's a good documentation where the above statement is taken there:

What do you think ?