aboutsummaryrefslogtreecommitdiff
path: root/vmime-master/doc/book/start.tex
blob: f169330152885ca4e02cef0ed817a5ec29f57a27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
\chapter{Getting Started}

% ============================================================================
\section{Using VMime in your programs}

First, make sure you have successfully compiled and installed VMime using the
instructions described in Chapter \ref{chapter_building}. To use VMime in your
program, you simply have to include VMime headers:

\begin{lstlisting}
#include <vmime/vmime.hpp>
\end{lstlisting}

\vnote{for versions older than 0.6.1, include $<$vmime/vmime$>$.}

As of version 0.6.1, VMime uses {\vcode pkg-config} to simplify compiling and
linking with VMime. The {\vcode pkg-config} utility is used to detect the
appropriate compiler and linker flags needed for a library.

You can simply build your program with:

\begin{verbatim}
   $ g++ `pkg-config --cflags --libs vmime` -static -o myprog myprog.cpp
\end{verbatim}

to use the static version, or with:

\begin{verbatim}
   $ g++ `pkg-config --cflags vmime` -o myprog myprog.cpp `pkg-config --libs vmime`
\end{verbatim}

to use the shared version.

\vnote{it is highly recommended that you link your program against the shared
version of the library.}

All VMime classes and global functions are defined in the namespace
{\vcode vmime}, so prefix explicitely all your declarations which use VMime
with {\vcode vmime::}, or import the {\vcode vmime} namespace into the global
namespace with the C++ keywork {\vcode using} (not recommended, though).


% ============================================================================
\section{If you can not (or do not want to) use {\vcode pkg-config}}

{\bf Linking with the shared library (.so):} compile your program with the
{\vcode -lvmime} flag. You can use the -L path flag if the library file is
not in a standard path (ie. not in /usr/lib or /usr/local/lib).

\vnote{if you want to link your program with the shared version of VMime
library, make sure the library has been compiled using CMake build system
({\vcode make}, then {\vcode make install}). When you compile with SCons,
only the static library is built and installed.}

{\bf Linking with the static library (.a):} follow the same procedure as for
shared linking and append the flag -static to force static linking. Although
static linking is possible, you are encouraged to use the shared (dynamic)
version of the library.


% ============================================================================
\section{Platform-dependent code}

While the most part of VMime code is pure ANSI C++, there are some features
that are platform-specific: file management (opening/reading/writing files),
network code (socket, DNS resolution) and time management. All the
non-portable stuff is done by a bridge object called a platform handler (see
{\vcode vmime::platform}).

If your platform is POSIX-compatible (eg. GNU/Linux, *BSD) or is Windows,
then you are lucky: VMime has built-in support for these platforms. If not,
don't worry, the sources of the built-in platform handlers are very well
documented, so writing you own should not be very difficult.

If your VMime version is $<=$ 0.9.1, you should tell VMime which platform
handler you want to use at the beginning of your program (before using
\emph{any} VMime object, or calling \emph{any} VMime global function).

So, if your platform is POSIX, your program should look like this:

\begin{lstlisting}[caption={Initializing VMime and the platform handler}]
#include <vmime/vmime.hpp>
#include <vmime/platforms/posix/posixHandler.hpp>

int main() {

   vmime::platform::
      setHandler <vmime::platforms::posix::posixHandler>();

   // Now, you can use VMime
   // ...do what you want, it's your program...
}
\end{lstlisting}

For using VMime on Windows, include
{\vcode vmime/platforms/windows/windowsHandler.hpp} and use the following line
to initialize the platform handler:

\begin{lstlisting}
vmime::platform::
   setHandler <vmime::platforms::windows::windowsHandler>();
\end{lstlisting}

\vnote{since version 0.9.2, this is not needed any more: the platform
handler is installed automatically using the platform detected during the
build configuration.}

\vnote{since version 0.8.1, {\vcode vmime::platformDependant} was renamed
to {\vcode vmime::platform}. The old name has been kept for compatibility
but it is recommended that you update your code, if needed.}