English version
Accueil     Ŕ propos     Téléchargement     Ressources     Contactez-nous    
Browse thread
What's the purpose of the static library?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alain Frisch <alain@f...>
Subject: Re: [Caml-list] What's the purpose of the static library?
Richard Jones wrote:
> File: library.cma ------------------------------
> 
> This is just a set of *.cmo files combined together.
> 
> Created by: 'ocamlc -a'
> 
> Used: Same as for module.cmo

.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