Antw: Re: [asterisk-dev] How to bind extern include files or libs into * 1.4

Russell Bryant russell at
Fri Apr 20 12:22:53 MST 2007

Hoai-Anh Ngo-Vi wrote:
> For basical understanding. When I write something for 1.4, let's say app_superprog.c, using external libraries (e.g MySQL). Could I add the mentioned things to ASTCFLAGS and ASTLDFLAGS in apps/Makefile?

The short answer is yes, that will work.

The long answer is that if you are writing a module that you intend to 
get merged back into the main Asterisk source tree, this is not the way 
you would do it.  I'm not sure if I ever really documented this, so I'll 
do a brief rundown here.  Let's use pbx_dundi.c and zlib as an example.

1) Add the library to build_tools/  In this file, we 


The configure script will set "ZLIB=0" or "ZLIB=1" in the generated file 
build_tools/menuselect-deps to indicate whether the library was found or 

2) Add the library to  In this file, we have:


The configure script will set these variables in the generated makeopts 
file when zlib is found.  It will automatically contain the information 
you would have needed to add to ASTCFLAGS or ASTLDFLAGS, and will be 
automatically used for building the appropriate module.

3) The configure script needs to check for whatever library your module 
uses.  In, you will see the following couple of lines:

AST_EXT_LIB_SETUP([ZLIB], [zlib], [z])

AST_EXT_LIB_CHECK([ZLIB], [z], [compress], [zlib.h])

This is the most basic way to add a new check for a library.  These 
macros exist in acinclude.m4.  They handle providing an option to the 
configure script to explicitly disable use of this library, as well as 
provide the ability to provide a path to where to find it.

"./configure --help" shows:

   --with-z=PATH           use zlib files in PATH

So, you can run "./configure --without-z" or "./configure --with-z=yes" 
or "./configure --with-z=/usr/src/zlib".

There are a couple more important things that these macros will do.

4) Set some information in the module itself to indicate that it depends 
on the library.  In pbx_dundi, we have this special block:


This tells the build system that pbx_dundi depends on zlib.  So, 
menuselect will not let you select it if it is not found.  Also, the 
Makefile will automatically include the information from ZLIB_INCLUDE 
and ZLIB_LIB for building the module.

That should be everything.  There are some more complicated examples in 
the tree.  For example, chan_zap can use libpri and libss7, but it does 
not require it for it to be compiled and installed.  The build system 
accounts for all of that.

Russell Bryant
Software Engineer
Digium, Inc.

More information about the asterisk-dev mailing list