caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] linking order of C libraries.
@ 2004-02-11  9:21 Yamagata Yoriyuki
  2004-02-11 12:37 ` Jacques Garrigue
  2004-02-20 19:33 ` ecc+
  0 siblings, 2 replies; 3+ messages in thread
From: Yamagata Yoriyuki @ 2004-02-11  9:21 UTC (permalink / raw)
  To: caml-list

It would be dumb to ask, but what is the effect of order in which C
libraries are given to ocamlc?  I ask because when I gave the command
line something like

 ocamlc -custom -I +camlp4 -I .. -I ../lib gramlib.cma -o mana\
 swig.cmo stub_helpers.o stub_wrap.o stub.cmo mana.cmo parse.cmo\
 ../lib/libchasen.a -cclib -lstdc++

then it succeeded, but if I gave

ocamlc -custom -I +camlp4 -I .. -I ../lib gramlib.cma -o mana\
../lib/libchasen.a swig.cmo stub_helpers.o stub_wrap.o stub.cmo\
mana.cmo parse.cmo -cclib -lstdc++

then it emits a lot of "undefined reference" errors.  (Only difference
is the location of ../lib/libchasen.a)

Is there a documentation I have overlooked?

--
Yamagata Yoriyuki

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] linking order of C libraries.
  2004-02-11  9:21 [Caml-list] linking order of C libraries Yamagata Yoriyuki
@ 2004-02-11 12:37 ` Jacques Garrigue
  2004-02-20 19:33 ` ecc+
  1 sibling, 0 replies; 3+ messages in thread
From: Jacques Garrigue @ 2004-02-11 12:37 UTC (permalink / raw)
  To: yoriyuki; +Cc: caml-list

From: Yamagata Yoriyuki <yoriyuki@mbg.ocn.ne.jp>
> It would be dumb to ask, but what is the effect of order in which C
> libraries are given to ocamlc?  I ask because when I gave the command
> line something like
> 
>  ocamlc -custom -I +camlp4 -I .. -I ../lib gramlib.cma -o mana\
>  swig.cmo stub_helpers.o stub_wrap.o stub.cmo mana.cmo parse.cmo\
>  ../lib/libchasen.a -cclib -lstdc++
> 
> then it succeeded, but if I gave
> 
> ocamlc -custom -I +camlp4 -I .. -I ../lib gramlib.cma -o mana\
> ../lib/libchasen.a swig.cmo stub_helpers.o stub_wrap.o stub.cmo\
> mana.cmo parse.cmo -cclib -lstdc++
> 
> then it emits a lot of "undefined reference" errors.  (Only difference
> is the location of ../lib/libchasen.a)

The order of the C libraries only changes their order on the
command-line passed to the system linker.
IIRC, the order in which they are passed to the linker is the
same order as on the command-line, but the rule is more subtle for C
libraries specified by a .cma, as some C linkers only resolve
references in libraries occuring after an object on the command-line,
while ocaml expects (ocaml) libraries to appear before they are
referenced. (The exact behaviour is specified somewhere in the
manual.) 

The problem you describe is system dependent: most linkers accept
libraries in any order, but some have the above described restriction.
I believe this was the case on Solaris until 2.6 or 7 for instance.
On such systems you must be careful about linking order, and ocaml can
do very little about it, except providing a way to specify this order.

Cheers,

Jacques Garrigue

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] linking order of C libraries.
  2004-02-11  9:21 [Caml-list] linking order of C libraries Yamagata Yoriyuki
  2004-02-11 12:37 ` Jacques Garrigue
@ 2004-02-20 19:33 ` ecc+
  1 sibling, 0 replies; 3+ messages in thread
From: ecc+ @ 2004-02-20 19:33 UTC (permalink / raw)
  To: caml-list

On Wed, Feb 11, 2004 at 06:21:15PM +0900, Yamagata Yoriyuki wrote:
> It would be dumb to ask, but what is the effect of order in which C
> libraries are given to ocamlc?

This is from the man page for GNU ld:

    The  linker will search an archive only once, at the location where
    it is specified on the command line.  If the archive defines a sym-
    bol  which  was  undefined in some object which appeared before the
    archive on the command line, the linker will include the  appropri-
    ate  file(s)  from the archive.  However, an undefined symbol in an
    object appearing later on the  command  line  will  not  cause  the
    linker to search the archive again.

    See  the -( option for a way to force the linker to search archives
    multiple times.

    You may list the same archive multiple times on the command line.

I didn't know about the "-(" and "-)" options.  Perhaps the ld
commands generated by the ocaml tools should use this to make library
order less error-prone?

-- 
Eric C. Cooper          e c c @ c m u . e d u

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-02-20 19:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-11  9:21 [Caml-list] linking order of C libraries Yamagata Yoriyuki
2004-02-11 12:37 ` Jacques Garrigue
2004-02-20 19:33 ` ecc+

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