manpagez: man pages & more
info gpgrt
Home | html | info | man

File: gpgrt.info,  Node: Building sources,  Next: Building sources using Automake,  Prev: Header,  Up: Preparation

2.2 Building sources
====================

If you want to compile a source file including the 'gpg-error.h' header
file, you must make sure that the compiler can find it in the directory
hierarchy.  This is accomplished by adding the path to the directory in
which the header file is located to the compilers include file search
path (via the '-I' option).

   However, the path to the include file is determined at the time the
source is configured.  To solve this problem, Libgpg-error ships with a
pkg-config file: gpg-error.pc.

   The options that need to be added to the compiler invocation at
compile time are output by the '--cflags' option to 'pkg-config'.  The
following example shows how it can be used at the command line:

     gcc -c foo.c $(pkg-config --cflags gpg-error)

   Adding the output of 'pkg-config --cflags gpg-error' to the
compiler’s command line will ensure that the compiler can find the
Libgpg-error header file.

   A similar problem occurs when linking the program with the library.
Again, the compiler has to find the library files.  For this to work,
the path to the library files has to be added to the library search path
(via the '-L' option).  For this, the option '--libs' to 'pkg-config'
can be used.  The example shows how to link 'foo.o' with the
Libgpg-error library to a program 'foo'.

     gcc -o foo foo.o $(pkg-config --libs gpg-error)

   Of course you can also combine both examples to a single command by
specifying both options to 'pkg-config':

     gcc -o foo foo.c $(pkg-config --cflags --libs gpg-error)

   For GnuPG and its friends, which are usually needed to be built
earlier in a stage of OS bootstrap, Libgpg-error ships the small helper
program 'gpgrt-config'.  This helper program is a sort of 'pkg-config'
replacement for limited environment, supporting cross compilation, as
well as multilib and multi-arch installation.  Note that 'gpgrt-config'
is not for general use for other programs.  'gpgrt-config' requires
invocation with the option '--lib=' so that it locates the appropriate
path to 'gpg-error.pc'.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.