* How can I convince ocamlbuild to link a library instead of object files?
@ 2007-10-17 15:10 Alan Falloon
2007-11-21 12:53 ` [Caml-list] " Nicolas Pouillard
0 siblings, 1 reply; 2+ messages in thread
From: Alan Falloon @ 2007-10-17 15:10 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 960 bytes --]
I am working on a project in ocaml that has a number of libraries that
it depends on that are being concurrently developed.
I can easily set up ocamlbuild to build the binaries and the libraries,
however the binaries are always built from the object files that are
packed into the library even if I tell it to link in the library via a
plugin.
I have attached an interactive script (lightly edited for clarity). The
thing to notice is that when it links main.byte it still includes
hello.cmo and world.cmo even though they are in hw.cma. This works for
the bytecode linking, but its a disaster for native code.
Is there some way to remove the object files from the link line in the
plugin? or am I missing some trick? It doesn't matter if the library
sources are in a different directory, if its included (and it has to be
included or ocamlbuild won't build the lib) then ocamlbuild will find
the object files and use them.
Thanks,
Alan Falloon
[-- Attachment #2: ocamlbuild-lib-example --]
[-- Type: text/plain, Size: 1669 bytes --]
Script started on Wed Oct 17 10:55:12 2007
% ls
_tags hello.ml hw.mllib main.ml myocamlbuild.ml world.ml
% cat _tags
<main.*>: use_hw
% cat hello.ml
let hello () = Printf.printf "hello "
% cat world.ml
let world () = Printf.printf "world!\n"
% cat main.ml
let () = Hello.hello (); World.world ()
% cat myocamlbuild.ml
open Ocamlbuild_plugin;;
open Command;;
dispatch begin
function After_rules ->
flag ["ocaml"; "use_hw"; "link"; "byte"] (P "hw.cma");
flag ["ocaml"; "use_hw"; "link"; "native"] (P "hw.cmxa");
dep ["ocaml"; "use_hw"; "link"; "byte"] ["hw.cma"];
dep ["ocaml"; "use_hw"; "link"; "native"] ["hw.cmxa"]
| _ -> ()
end
% ocamlbuild -classic-display main.byte
ocamlopt.opt -I +ocamlbuild unix.cmxa ocamlbuildlib.cmxa myocamlbuild.ml ocamlbuild.cmx -o myocamlbuild
ocamldep.opt -modules main.ml > main.ml.depends
ocamldep.opt -modules hello.ml > hello.ml.depends
ocamldep.opt -modules world.ml > world.ml.depends
ocamlc.opt -c -o hello.cmo hello.ml
ocamlc.opt -c -o world.cmo world.ml
ocamlc.opt -c -o main.cmo main.ml
ocamlc.opt -a hello.cmo world.cmo -o hw.cma
ocamlc.opt hw.cma hello.cmo world.cmo main.cmo hw.cma -o main.byte
% ocamlbuild -classic-display main.native
ocamlopt.opt -c -o hello.cmx hello.ml
ocamlopt.opt -c -o world.cmx world.ml
ocamlopt.opt -c -o main.cmx main.ml
ocamlopt.opt -a hello.cmx world.cmx -o hw.cmxa
ocamlopt.opt hw.cmxa hello.cmx world.cmx main.cmx hw.cmxa -o main.native
+ ocamlopt.opt hw.cmxa hello.cmx world.cmx main.cmx hw.cmxa -o main.native
<lots of link errors...>
collect2: ld returned 1 exit status
Error during linking
Command exited with code 2.
%
Script done on Wed Oct 17 10:56:29 2007
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] How can I convince ocamlbuild to link a library instead of object files?
2007-10-17 15:10 How can I convince ocamlbuild to link a library instead of object files? Alan Falloon
@ 2007-11-21 12:53 ` Nicolas Pouillard
0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Pouillard @ 2007-11-21 12:53 UTC (permalink / raw)
To: alan.falloon; +Cc: caml-list
Excerpts from alan.falloon's message of Wed Oct 17 17:10:21 +0200 2007:
> I am working on a project in ocaml that has a number of libraries that
> it depends on that are being concurrently developed.
>
> I can easily set up ocamlbuild to build the binaries and the libraries,
> however the binaries are always built from the object files that are
> packed into the library even if I tell it to link in the library via a
> plugin.
>
> I have attached an interactive script (lightly edited for clarity). The
> thing to notice is that when it links main.byte it still includes
> hello.cmo and world.cmo even though they are in hw.cma. This works for
> the bytecode linking, but its a disaster for native code.
>
> Is there some way to remove the object files from the link line in the
> plugin? or am I missing some trick? It doesn't matter if the library
> sources are in a different directory, if its included (and it has to be
> included or ocamlbuild won't build the lib) then ocamlbuild will find
> the object files and use them.
(Sorry for the late reply)
Can you try to declare the library using the ocaml_lib function.
Something like <<ocaml_lib "hw">> in your myocamlbuild.ml, otherwise the
use_hw tag is not used.
HTH,
--
Nicolas Pouillard aka Ertai
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-11-21 12:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-17 15:10 How can I convince ocamlbuild to link a library instead of object files? Alan Falloon
2007-11-21 12:53 ` [Caml-list] " Nicolas Pouillard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox