I noticed there are some static libraries(.a) installed with ocaml, for
example, /usr/lib/ocaml/bigarray.a. What's the purpose of those static
libraries? Thanks a lot.
Regards,
Bill
_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
They contain (natively) compiled OCaml code. An OCaml library compiled
in native mode (usually) consists of a .a and a .cmxa file, the former
containing OCaml-specific information.
They are not to be confused with lib*.a files, which contain compiled C
stubs, and are needed for generating native-code executables, and
bytecode ones in -custom mode.
Cheers,
--
Stéphane
Thanks a lot for your information. And we'd like to know more about the
OCaml library architectures, like on what situation dynamic libraries
are used, and when static libraries are used, and so on.. Really
appreciate if you could point me to a document that can help on this topic.
Regards,
Bill
Stéphane Glondu 已写入:
> bill yan a écrit :
>
>> I noticed there are some static libraries(.a) installed with ocaml, for
>> example, /usr/lib/ocaml/bigarray.a. What's the purpose of those static
>> libraries? Thanks a lot.
>
>
> They contain (natively) compiled OCaml code. An OCaml library compiled
> in native mode (usually) consists of a .a and a .cmxa file, the former
> containing OCaml-specific information.
>
> They are not to be confused with lib*.a files, which contain compiled
> C stubs, and are needed for generating native-code executables, and
> bytecode ones in -custom mode.
>
>
> Cheers,
>
_______________________________________________
It's not particularly well-documented, and it changes a little in
3.11, but below is my understanding. There are probably errors in
what follows. If someone can correct the errors then I'll publish a
corrected document.
File: module.cmi ------------------------------
Contains the compiled interface for Module, essentially equivalent to
the contents of the *.mli file but in a compiled/binary form which the
compiler can load easily.
Created by: 'ocamlc -c module.mli', or if module.mli doesn't exist
then 'ocamlc -c module.ml' (also by 'ocamlopt -c module.ml').
Used: Whenever the toplevel or compiler uses any symbol Module.foo,
this file is consulted.
File: module.cmo ------------------------------
Contains the bytecode of the implementation of Module.
Created by: 'ocamlc -c module.ml'
Used: When linking bytecode programs, or creating bytecode libraries
(*.cma), or by the toplevel when you use #load, or by Dynlink.
File: library.cma ------------------------------
This is just a set of *.cmo files combined together.
Created by: 'ocamlc -a'
Used: Same as for module.cmo
Files: module.o and module.cmx --------------------
These two files go together. The *.o file contains compiled native
code in the normal system object file format. The *.cmx file contains
metainformation about the machine code in the *.o file.
Created by: 'ocamlopt -c module.ml'
Used: When linking native code programs, or creating native code
libraries.
Note(1): You normally never need to specify the *.o files by hand. On
the command line when the compiler sees a *.cmx file, it looks for the
corresponding *.o file if it needs it.
Note(2): It is thought that the *.cmx file needs to be around even
when linking a library (*.cmxa) file in order to do cross-module
function inlining. Both the Debian & Fedora packaging rules specify
that *.cmx files be kept around for this reason. Whether this is
really true or not is not certain.
File: library.a and library.cmxa --------------------
These files go together. The *.a file contains compiled native code
in the normal system archive format. The *.cmxa file contains
metainformation.
Created by: 'ocamlopt -a'
Used: Same as for *.o/*.cmx
Note: You normally never need to specify the *.a files by hand.
File: dlllibrary.so and liblibrary.a --------------------
These files are created and used when a bytecode or native library
contains some C code. 'dllXXX.so' is created for use by the toplevel
and contains the compiled C code. 'libXXX.a' is created for use by
compiled standalone programs and also contains the same compiled C
code.
Created by: 'ocamlmklib -o library *.o *.cmo'
or: 'ocamlmklib -o library *.o *.cmx'
Used: dlllibrary.so is dlopen(2)'d by the toplevel.
liblibrary.a is linked in standalone programs.
Note: You normally never need to specify these files by hand. The
*.cma/*.cmxa file contains the necessary information to find these
files if necessary.
----------------------------------------------------------------------
Rich.
--
Richard Jones
Red Hat
> And we'd like to know more about the OCaml library architectures,
> like on what situation dynamic libraries are used, and when static
> libraries are used, and so on..
This depends on what _you_ want. The tradeoffs of dynamic vs static
linking are mostly as in any other language.
> Really appreciate if you could point me to a document that can help
> on this topic.
o Part III of the manual (especially ocamlc ocamlopt and interfacing
with C). http://caml.inria.fr/pub/docs/manual-ocaml/
o Chapter 7 and 12 of the Oreilly book http://caml.inria.fr/pub/docs/oreilly-book/html/index.html
Best,
Daniel
cma files also contain extra linking directives like references to C
libraries.
> Files: module.o and module.cmx --------------------
>
> These two files go together. The *.o file contains compiled native
> code in the normal system object file format. The *.cmx file contains
> metainformation about the machine code in the *.o file.
>
> Created by: 'ocamlopt -c module.ml'
>
> Used: When linking native code programs, or creating native code
> libraries.
.. or compiling other modules.
>
> Note(1): You normally never need to specify the *.o files by hand. On
> the command line when the compiler sees a *.cmx file, it looks for the
> corresponding *.o file if it needs it.
>
> Note(2): It is thought that the *.cmx file needs to be around even
> when linking a library (*.cmxa) file in order to do cross-module
> function inlining. Both the Debian & Fedora packaging rules specify
> that *.cmx files be kept around for this reason. Whether this is
> really true or not is not certain.
This is true.
cmx files are needed when they contain modules compiled with -for-pack.
Otherwise, they are optional. Hiding them to the compiler is a way to
get fewer dependencies (more separate compilation).
Note that the .o extension is actually .obj for the MSVC ports under
Windows.
> File: library.a and library.cmxa --------------------
>
> These files go together. The *.a file contains compiled native code
> in the normal system archive format. The *.cmxa file contains
> metainformation.
>
> Created by: 'ocamlopt -a'
>
> Used: Same as for *.o/*.cmx
>
> Note: You normally never need to specify the *.a files by hand.
(.lib for MSVC ports)
> File: dlllibrary.so and liblibrary.a --------------------
>
> These files are created and used when a bytecode or native library
> contains some C code. 'dllXXX.so' is created for use by the toplevel
> and contains the compiled C code. 'libXXX.a' is created for use by
> compiled standalone programs and also contains the same compiled C
> code.
>
> Created by: 'ocamlmklib -o library *.o *.cmo'
> or: 'ocamlmklib -o library *.o *.cmx'
>
> Used: dlllibrary.so is dlopen(2)'d by the toplevel.
> liblibrary.a is linked in standalone programs.
dlllibrary.so is also used by the bytecode interpreter, by Dynlink and
by ocamlc (to check for the availability of C primitives at compile time).
-- Alain
Richard,
This is a wonderful answer! It should go onto the wiki or in the FAQ.
One nitpick...
cma (and .cmxa) files should not be used for creating libraries
(as .cmo and .cmx files can (and should) be). I.e., don't like a
library into a library. Doing so will give a compiler error:
X.cma is not a compilation unit description.
Regards,
Chris
Hi Richard,
do you have a public place where this document (patched with the
received comments) is available? If so please let us know (so that we
can reference if from the Debian OCaml packaging policy), if not I will
integrate it directly in the policy document, which is in fact publicly
available on the web.
Cheers.
--
Stefano Zacchiroli -*- PhD in Computer Science \ PostDoc @ Univ. Paris 7
zack@{upsilon.cc,pps.jussieu.fr,debian.org} -<>- http://upsilon.cc/zack/
I'm still an SGML person,this newfangled /\ All one has to do is hit the
XML stuff is so ... simplistic -- Manoj \/ right keys at the right time
http://ocaml-tutorial.org/filenames
is probably the best place. I've added a link to my posting
temporarily.
Rich.
--
Richard Jones
Red Hat
_______________________________________________
Do you think *.cmx and *.o should be shipped?
Is *.cmx enough?
Regards
Sylvain Le Gall
Thanks a lot for your help on this topic. Now I have a quesiton for the
following part:
File: library.a and library.cmxa --------------------
These files go together. The *.a file contains compiled native code
in the normal system archive format. The *.cmxa file contains
metainformation.
By my understanding, unlike dlllibrary.so and liblibrary.a give user an
option to choose compile dynamically or staticly, it seems for
library.a, user can only choose static method. Does that mean "compiled
native code" can only be staticly linked to user's application?
Thanks & Best regards,
Bill
Richard Jones ???:
In OCaml 3.11, it will be possible to link native code (found in
library.a or module.o files) into .cmxs files that can be explicitly
loaded at runtime (with the same API as for bytecode Dynlink).
Alain
Alain Frisch 已写入:
bill yan 已写入: