| 1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" |
| 2 |
"http://www.w3.org/TR/REC-html40/loose.dtd"> |
| 3 |
<HTML> |
| 4 |
<HEAD> |
| 5 |
|
| 6 |
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| 7 |
<META name="GENERATOR" content="hevea 1.06-7 of 2001-11-14"> |
| 8 |
<TITLE> |
| 9 |
Using camlidl |
| 10 |
</TITLE> |
| 11 |
</HEAD> |
| 12 |
<BODY > |
| 13 |
<A HREF="main003.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A> |
| 14 |
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A> |
| 15 |
<A HREF="main005.html"><IMG SRC ="next_motif.gif" ALT="Next"></A> |
| 16 |
<HR> |
| 17 |
|
| 18 |
<H2><A NAME="htoc24">4</A> Using <TT>camlidl</TT></H2> |
| 19 |
<A NAME="toc21"></A> |
| 20 |
<H3><A NAME="htoc25">4.1</A> Overview</H3> |
| 21 |
The <TT>camlidl</TT> stub generator is invoked as follows: |
| 22 |
<PRE> |
| 23 |
camlidl <I>options</I> <I>file1</I>.idl <I>file2</I>.idl ... |
| 24 |
</PRE> |
| 25 |
For each file <I>f</I><TT>.idl</TT> given on the command line, <TT>camlidl</TT> |
| 26 |
generates the following files: |
| 27 |
<UL><LI> |
| 28 |
A Caml interface file <I>f</I><TT>.mli</TT> that defines the Caml view |
| 29 |
of the IDL file. It contains Caml definitions for the types declared |
| 30 |
in the IDL file, as well as declarations for the functions and the |
| 31 |
interfaces. |
| 32 |
<LI>A Caml implementation file <I>f</I><TT>.ml</TT> that implements the |
| 33 |
<I>f</I><TT>.mli</TT> file. |
| 34 |
<LI>A C source file <I>f</I><TT>_stubs.c</TT> that contains the stub functions for |
| 35 |
converting between C and Caml data representations. |
| 36 |
<LI>If the <TT>-header</TT> option is given, a C header file <I>f</I><TT>.h</TT> |
| 37 |
containing C declarations for the types declared in the IDL file. |
| 38 |
</UL> |
| 39 |
The generated <TT>.ml</TT> and <TT>.c</TT> files must be compiled and linked with |
| 40 |
the remainder of the Caml program.<BR> |
| 41 |
<BR> |
| 42 |
<A NAME="toc22"></A> |
| 43 |
<H3><A NAME="htoc26">4.2</A> Options</H3> |
| 44 |
The following command-line options are recognized by <TT>camlidl</TT>. |
| 45 |
<DL COMPACT=compact><DT><B><TT>-cpp</TT></B><DD> |
| 46 |
Pre-process the source IDL files with the C preprocessor. This option |
| 47 |
is set by default.<BR> |
| 48 |
<BR> |
| 49 |
<DT><B><TT>-D </TT> <I>symbol</I></B><B><TT>=</TT><I>value</I></B><DD> |
| 50 |
Define a preprocessor symbol. The option <TT>-D</TT><I>symbol</I><TT>=</TT><I>value</I> |
| 51 |
is passed to the C preprocessor. The <I>value</I> can be omitted, |
| 52 |
as in <TT>-D</TT> <I>symbol</I>, and defaults to <TT>1</TT>.<BR> |
| 53 |
<BR> |
| 54 |
<DT><B><TT>-header</TT></B><DD> |
| 55 |
Generate a C header file <I>f</I><TT>.h</TT> containing C declarations for the |
| 56 |
types and functions declared in the IDL file <I>f</I><TT>.c</TT>.<BR> |
| 57 |
<BR> |
| 58 |
<DT><B><TT>-I </TT> <I>dir</I></B><DD> |
| 59 |
Add the directory <I>dir</I> to the list of directories searched for |
| 60 |
<TT>.idl</TT> files, as given on the command line or recursively loaded |
| 61 |
by <TT><FONT COLOR=blue>import</FONT></TT> statements.<BR> |
| 62 |
<BR> |
| 63 |
<DT><B><TT>-keep-labels</TT></B><DD> |
| 64 |
Keep the Caml names of record labels as specified in the IDL file. |
| 65 |
Do not prefix them with the name of the enclosing struct, even if they |
| 66 |
appear in several struct definitions.<BR> |
| 67 |
<BR> |
| 68 |
<DT><B><TT>-nocpp</TT></B><DD> |
| 69 |
Suppresses the pre-processing of source IDL files.<BR> |
| 70 |
<BR> |
| 71 |
<DT><B><TT>-no-include</TT></B><DD> |
| 72 |
By default, <TT>camlidl</TT> emits a <TT>#include "</TT><I>f</I><TT>.h"</TT> statement in |
| 73 |
the file <I>f</I><TT>.c</TT> containing the generated C code. |
| 74 |
The <I>f</I><TT>.h</TT> header file being included is |
| 75 |
either the one generated by <TT>camlidl -header</TT>, or generated by another |
| 76 |
tool (such as Microsoft's <TT>midl</TT> compiler) from the IDL file, or |
| 77 |
hand-written. The <I>f</I><TT>.h</TT> file is assumed to provide all C type |
| 78 |
declarations needed for compiling the stub code.<BR> |
| 79 |
<BR> |
| 80 |
The <TT>-no-include</TT> option suppresses the automatic inclusion of the |
| 81 |
<I>f</I><TT>.h</TT> file. The IDL file should then include the right header |
| 82 |
files and provide the right type declarations via <TT><FONT COLOR=blue>quote</FONT></TT> statements.<BR> |
| 83 |
<BR> |
| 84 |
<DT><B><TT>-prefix-all-labels</TT></B><DD> |
| 85 |
Prefix all Caml names of record labels with the name of the enclosing |
| 86 |
struct. The default is to prefix only those labels that could cause |
| 87 |
ambiguity because they appear in several struct definitions.<BR> |
| 88 |
<BR> |
| 89 |
<DT><B><TT>-prepro</TT> <I>preprocessing-command</I></B><DD> |
| 90 |
Set the command that is executed to pre-process the source IDL files. |
| 91 |
The default is the C preprocessor.</DL> |
| 92 |
<A NAME="toc23"></A> |
| 93 |
<H3><A NAME="htoc27">4.3</A> The <TT>camlidldll</TT> script</H3> |
| 94 |
Under Windows, a <TT>bash</TT> script called <TT>camlidldll</TT> is provided to |
| 95 |
automate the construction of a DLL containing a COM component written |
| 96 |
in Caml.<BR> |
| 97 |
<BR> |
| 98 |
The script <TT>camlidldll</TT> accepts essentially the same command-line |
| 99 |
arguments and options as the <TT>ocamlc</TT> compiler. (It also accepts |
| 100 |
<TT>.tlb</TT> type library files on the command-line; see |
| 101 |
section <A HREF="main006.html#s-dispatch">6.3</A>, ``Dispatch interfaces'', for more |
| 102 |
information on type libraries.) |
| 103 |
It produces a DLL file that encapsulates the Caml and C object files |
| 104 |
given on the command line.<BR> |
| 105 |
<BR> |
| 106 |
Use <TT>regsvr32 /s </TT><I>file</I><TT>.dll</TT> to record the components in the |
| 107 |
system registry once it is compiled to a DLL.<BR> |
| 108 |
<BR> |
| 109 |
<HR> |
| 110 |
<A HREF="main003.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A> |
| 111 |
<A HREF="index.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A> |
| 112 |
<A HREF="main005.html"><IMG SRC ="next_motif.gif" ALT="Next"></A> |
| 113 |
</BODY> |
| 114 |
</HTML> |