Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007150OCaml~DO NOT USE (was: OCaml general)public2016-02-16 11:472017-05-27 02:39
Reporteryallop 
Assigned To 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusacknowledgedResolutionreopened 
PlatformOSOS Version
Product Version 
Target Version4.03.1+devFixed in Version 
Summary0007150: ocamlopt reorders linker options
DescriptionHere's a demonstration of unhelpful reordering behaviour involving options passed through by ocamlopt to the linker.

First, let's compile a couple of modules:

    $ ocamlopt -c a.ml b.ml

Next, we'll build a library from one of the modules with some linker options, passed via -cclib:

    $ ocamlopt -a -o liba.cmxa a.cmx -cclib -L/usr/adir/lib -cclib -L/usr/adir2/lib

Finally, we'll build an executable from the library and the other module, passing some more linker options:

    $ ocamlopt -verbose -o b.native b.cmx -cclib -L/usr/lib/bdir/ -cclib -v liba.cmxa -cclib -L/usr/bdir2/lib

Here's the linker invocation from the last step:

    gcc -o 'b.native' '-L/home/jeremy/.opam/4.02.3/lib/ocaml' '/tmp/camlstartup7c51ee.o' '/home/jeremy/.opam/4.02.3/lib/ocaml/std_exit.o' 'liba.a' 'b.o' '/home/jeremy/.opam/4.02.3/lib/ocaml/stdlib.a' '-L/usr/adir/lib' '-L/usr/adir2/lib' '-L/usr/lib/bdir/' '-v' '-L/usr/bdir2/lib' '/home/jeremy/.opam/4.02.3/lib/ocaml/libasmrun.a' -lm -ldl

In particular, note the order of the linker options

    '-L/usr/adir/lib' '-L/usr/adir2/lib' '-L/usr/lib/bdir/' '-v' '-L/usr/bdir2/lib'

Although liba.cmxa appeared between -L/usr/lib/bdir and -L/usr/bdir2/lib in the ocamlopt command line, in the gcc command line the options embedded in liba.cmxa have all been moved to the beginning of the line.

Moving the options in this way is a problem because the order of -L options is significant. Moving cmxa-embedded options to the beginning of the line results in those options taking precedence over whatever's specified on the command-line. On my system, for example, the lwt-unix.cmxa library embeds -L/usr/lib, which then appears at the beginning of the library search path. As a result system libraries are chosen before user-installed libraries, which is not usually the desired behaviour.

TagsNo tags attached.
Attached Files

- Relationships
related to 0005441resolved order of -ccopt and -cclib wrt other arguments 

-  Notes
(0015391)
doligez (administrator)
2016-02-24 17:02

Please read the discussion under 0005441.
(0015392)
yallop (developer)
2016-02-24 17:17

Thanks for the reference. Perhaps I can fix the immediate issue by using -ccopt rather than -cclib to pass -L options.
(0016872)
shinwell (developer)
2016-12-08 13:39

Given that 0005441 has been closed I believe this one can be too.
(0017804)
yallop (developer)
2017-05-18 12:37

I'm reopening this because 0005441 doesn't solve the problem.

I'd like the command line options


   -cclib -L/usr/bdir/lib liba.cmxa -cclib -L/usr/bdir2/lib


to embed the linker options from liba.cmxa between the linker option -L/usr/bdir/lib and -L/usr/bdir2/lib and there doesn't appear to be any way to achieve that with any combination of '-ccopt -Wl,' and '-cclib'.

- Issue History
Date Modified Username Field Change
2016-02-16 11:47 yallop New Issue
2016-02-24 17:02 doligez Note Added: 0015391
2016-02-24 17:03 doligez Relationship added related to 0005441
2016-02-24 17:03 doligez Status new => feedback
2016-02-24 17:17 yallop Note Added: 0015392
2016-02-24 17:17 yallop Status feedback => new
2016-02-25 15:53 doligez Status new => acknowledged
2016-02-25 15:53 doligez Target Version => 4.03.1+dev
2016-12-08 13:39 shinwell Note Added: 0016872
2016-12-08 13:39 shinwell Status acknowledged => closed
2016-12-08 13:39 shinwell Resolution open => no change required
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-03 17:55 doligez Category -OCaml general => -(deprecated) general
2017-03-03 18:01 doligez Category -(deprecated) general => ~deprecated (was: OCaml general)
2017-03-06 17:04 doligez Category ~deprecated (was: OCaml general) => ~DO NOT USE (was: OCaml general)
2017-05-18 12:37 yallop Note Added: 0017804
2017-05-18 12:37 yallop Status closed => feedback
2017-05-18 12:37 yallop Resolution no change required => reopened
2017-05-18 12:39 yallop Assigned To => yallop
2017-05-18 12:39 yallop Status feedback => new
2017-05-18 12:39 yallop Status new => acknowledged
2017-05-18 12:39 yallop Assigned To yallop =>


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker