[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This chapter deals with embedding the Serveez core library into standalone C/C++ applications and using it in order to write additional servers.
2.1 Compiling and linking How to compile and link against the library 2.2 A simple example A very small example showing the basics
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
When you have installed a version of Serveez passing the `configure'
script the $prefix
argument e.g. `./configure --prefix=/usr/local'
you will find the `libserveez' library in `/usr/local/lib' and the
include headers in `/usr/local/include'. If you want to compile a C
program using the Serveez API and link against the Serveez core library
libserveez
, which is `libserveez.so' at Unices and
`libserveez.dll' at Windows systems, you need to tell the compiler and
linker where to find the headers and libraries.
Most C compilers you can use will understand the following command line options for this purpose. The `-I' argument specifies the path to additional include headers, the `-L' argument the path to additional libraries and the `-l' argument the library itself to link against.
$ cc svztest.c -I/usr/local/include -o svztest -L/usr/local/lib -lserveez |
In order to obtain the correct compiler and linker flag you can also run the `serveez-config' script which gets installed with the Serveez package. The `serveez-config' script can be invoked with the following set of option.
-h, --help
-v, --version
-l, --ldflags
-c, --cflags
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following small example shows how to use the Serveez core library to
print the list of known network interface. As you will notice there are three
major steps to do: Include the library header with
#include <libserveez.h>
, initialize the library via svz_boot()
and finalize it via svz_halt()
. In between these calls you can use
all of the API functions, variables and macros described in
3. Embedding API.
#include <libserveez.h> /* Include the library header. */ int main (int argc, char **argv) { svz_boot (); /* Library initialization. */ svz_interface_list (); svz_halt (); /* Library finalization. */ return 0; } |
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |