libidn: Building the source

1 
1 2.4 Building the source
1 =======================
1 
1 If you want to compile a source file including e.g.  the ‘idna.h’ header
1 file, you must make sure that the compiler can find it in the directory
1 hierarchy.  This is accomplished by adding the path to the directory in
1 which the header file is located to the compilers include file search
1 path (via the ‘-I’ option).
1 
1    However, the path to the include file is determined at the time the
1 source is configured.  To solve this problem, ‘Libidn’ uses the external
1 package ‘pkg-config’ that knows the path to the include file and other
1 configuration options.  The options that need to be added to the
1 compiler invocation at compile time are output by the ‘--cflags’ option
1 to ‘pkg-config libidn’.  The following example shows how it can be used
1 at the command line:
1 
1      gcc -c foo.c `pkg-config libidn --cflags`
1 
1    Adding the output of ‘pkg-config libidn --cflags’ to the compilers
1 command line will ensure that the compiler can find e.g.  the idna.h
1 header file.
1 
1    A similar problem occurs when linking the program with the library.
1 Again, the compiler has to find the library files.  For this to work,
1 the path to the library files has to be added to the library search path
1 (via the ‘-L’ option).  For this, the option ‘--libs’ to ‘pkg-config
1 libidn’ can be used.  For convenience, this option also outputs all
1 other options that are required to link the program with the ‘libidn’
1 library.  The example shows how to link ‘foo.o’ with the ‘libidn’
1 library to a program ‘foo’.
1 
1      gcc -o foo foo.o `pkg-config libidn --libs`
1 
1    Of course you can also combine both examples to a single command by
1 specifying both options to ‘pkg-config’:
1 
1      gcc -o foo foo.c `pkg-config libidn --cflags --libs`
1