# Asterisk Project : Installing pjproject

Added by mjordan , edited by rnewton on Aug 24, 2013

Asterisk 12 contains a new SIP stack that is based on pjproject. Some changes in pjproject were needed for Asterisk 12. The largest change were modifications made to the pjproject build system that allowed it to build shared object libraries. Unlike Asterisk 11 - which embedded pjproject in order to utilize its ICE/STUN/TURN libraries in its RTP engine - Asterisk 12 dynamically links to pjproject.

As a result, currently, versions of pjproject that can be downloaded from www.pjsip.org will not work with Asterisk 12. This includes the version of pjproject embedded in Asterisk 11.

The Asterisk 12 compatible version of pjproject is available on github, or - depending on your Linux distribution - available as a package. This wiki page provides detailed instructions on building and install pjproject for Asterisk 12.

If you have previously installed a version of pjproject, you must remove that version of pjproject prior to building and installing the Asterisk 12 compatible version of pjproject. See Uninstalling pjproject for more information.

## Building and Installing pjproject from Source

### Downloading pjproject

1. If you do not have git, install git on your local machine.

   Downloading and installing `git` are beyond the scope of these instructions.

2. Checkout pjproject from the github repo:

       # git clone https://github.com/asterisk/pjproject pjproject
       # cd pjproject

   And that's it!

### Building and Installing pjproject

pjproject embeds a number of third party libraries which can conflict with installed versions of those libraries. Thus, building pjproject is highly dependent on your distribution of Linux as well as what third party libraries are already installed on your system. A number of configuration options are available to disable these libraries in pjproject and custom tailor it to your system. The table below outlines common ones that may be needed for a typical installation.

Library | Configure option | Notes
--- | --- | ---
libspeex shared objects | `--with-external-speex` | Make sure that the library development headers are accessible from pjproject. The CFLAGS and LDFLAGS environment variables may be used to set the include/lib paths.
libsrtp shared objects | `--with-external-srtp` | Make sure that the library development headers are accessible from pjproject. The CFLAGS and LDFLAGS environment variables may be used to set the include/lib paths.
GSM codec | `--with-external-gsm` | Make sure that the library development headers are accessible from pjproject. The CFLAGS and LDFLAGS environment variables may be used to set the include/lib paths.
Disable sound | `--disable-sound` | Let Asterisk perform sound manipulations.
Disable resampling | `--disable-resample` | Let Asterisk perform resample operations.
Disable video | `--disable-video` | Disable video support in pjproject's media libraries. This is not used by Asterisk.

These are some of the more common options used to disable third party libraries in pjproject. However, other options may be needed depending on your system - see `configure --help` for a full list of configure options you can pass to pjproject.

1. In the pjproject source directory:

       # ./configure --prefix=/usr --enable-shared

   You must specify `--enable-shared` in order to build the shared objects for Asterisk. `--prefix` should be set to the base path of the `lib` directory where the shared objects will be installed.

2. Build pjproject:

       # make dep
         ...
       # make
         ...
            output/sample-x86_64-unknown-linux-gnu/vid_streamutil.o -L/home/mjordan/projects/pjproject/pjlib/lib -L/home/mjordan/projects/pjproject/pjlib-util/lib -L/home/mjordan/projects/pjproject/pjnath/lib -L/home/mjordan/projects/pjproject/pjmedia/lib -L/home/mjordan/projects/pjproject/pjsip/lib -L/home/mjordan/projects/pjproject/third_party/lib        -lpjsua -lpjsip-ua -lpjsip-simple -lpjsip -lpjmedia-codec -lpjmedia -lpjmedia-videodev -lpjmedia-audiodev -lpjnath -lpjlib-util  -lmilenage -lsrtp -lresample -lgsmcodec -lspeex -lilbccodec -lg7221codec -lportaudio  -lpj -lm -luuid -lm -lnsl -lrt -lpthread  -lasound -lcrypto -lssl
       make[2]: Leaving directory `/home/mjordan/projects/pjproject/pjsip-apps/build'
       make[1]: Leaving directory `/home/mjordan/projects/pjproject/pjsip-apps/build'

3. Install pjproject

       # make install
       ...
       dev -lpjnath -lpjlib-util  -lmilenage -lsrtp -lresample -lgsmcodec -lspeex -lilbccodec -lg7221codec -lportaudio  -lpj -lm -luuid -lm -lnsl -lrt -lpthread  -lasound -lcrypto -lssl!" | \
       	sed -e "s!@PJ_INSTALL_CFLAGS@!-I/usr/include -DPJ_AUTOCONF=1	-O2 -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1 -fPIC!" > //usr/lib/pkgconfig/libpjproject.pc

4. Update shared library links and verify that pjproject has been installed in the target location:

       # ldconfig
       # ldconfig -p | grep pj
       	libpjsua.so (libc6,x86-64) => /usr/lib/libpjsua.so
       	libpjsip.so (libc6,x86-64) => /usr/lib/libpjsip.so
       	libpjsip-ua.so (libc6,x86-64) => /usr/lib/libpjsip-ua.so
       	libpjsip-simple.so (libc6,x86-64) => /usr/lib/libpjsip-simple.so
       	libpjnath.so (libc6,x86-64) => /usr/lib/libpjnath.so
       	libpjmedia.so (libc6,x86-64) => /usr/lib/libpjmedia.so
       	libpjmedia-videodev.so (libc6,x86-64) => /usr/lib/libpjmedia-videodev.so
       	libpjmedia-codec.so (libc6,x86-64) => /usr/lib/libpjmedia-codec.so
       	libpjmedia-audiodev.so (libc6,x86-64) => /usr/lib/libpjmedia-audiodev.so
       	libpjlib-util.so (libc6,x86-64) => /usr/lib/libpjlib-util.so
       	libpj.so (libc6,x86-64) => /usr/lib/libpj.so

5. Finally, verify that Asterisk detects the pjproject libraries. In your Asterisk 12 source directory:

       # ./configure
       # make menuselect

6. Browse to the Resource Modules category and verify that the `res_pjsip` modules are enabled

### Issues and Workarounds

Issue | Resolution
--- | ---
When building pjproject, errors about an ARM codec are displayed:
    output/pjmedia-codec-x86_64-unknown-linux-gnu/opencore_amr.o:(.rodata+0x60): multiple definition of `pjmedia_codec_amrnb_framelenbits'
    output/pjmedia-codec-x86_64-unknown-linux-gnu/opencore_amr.o:(.rodata+0x60): first defined here
    output/pjmedia-codec-x86_64-unknown-linux-gnu/opencore_amr.o:(.rodata+0x80): multiple definition of `pjmedia_codec_amrnb_framelen'
    output/pjmedia-codec-x86_64-unknown-linux-gnu/opencore_amr.o:(.rodata+0x80): first defined here
    output/pjmedia-codec-x86_64-unknown-linux-gnu/opencore_amr.o:(.rodata+0x20): multiple definition of `pjmedia_codec_amrwb_framelenbits'
    output/pjmedia-codec-x86_64-unknown-linux-gnu/opencore_amr.o:(.rodata+0x20): first defined here
    output/pjmedia-codec-x86_64-unknown-linux-gnu/opencore_amr.o:(.rodata+0x40): multiple definition of `pjmedia_codec_amrwb_framelen'
    output/pjmedia-codec-x86_64-unknown-linux-gnu/opencore_amr.o:(.rodata+0x40): first defined here
    ...
| You already have the AMR codec installed. Run `configure` with the `--disable-opencore-amr` option specified.
When building pjproject, linker errors referring to various video methods are displayed:
    /home/mjordan/projects/pjproject/pjmedia/lib/libpjmedia-videodev.so: undefined reference to `pjmedia_format_init_video'
    /home/mjordan/projects/pjproject/pjmedia/lib/libpjmedia.so: undefined reference to `pjmedia_video_format_mgr_instance'
    /home/mjordan/projects/pjproject/pjmedia/lib/libpjmedia-videodev.so: undefined reference to `pjmedia_format_get_video_format_detail'
    /home/mjordan/projects/pjproject/pjmedia/lib/libpjmedia-videodev.so: undefined reference to `pjmedia_get_video_format_info'
| Run `configure` with either or both `--disable-video` or `--disable-v4l2`
After building pjproject, the dump provided by `ldconfig -p` doesn't display any libraries. | Run `ldconfig` to re-configure dynamic linker run-time bindings
After building and installing pjproject, Asterisk fails to detect any of the libraries (the entries cannot be selected in menuselect) | Verify that Asterisk's `config.log` shows the following:
    configure:23029: checking for PJPROJECT
    configure:23036: $PKG_CONFIG --exists --print-errors "libpjproject"
    Package libpjproject was not found in the pkg-config search path.
    Perhaps you should add the directory containing `libpjproject.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'libpjproject' found
Make sure you have `pkg-config` installed on your system. pjproject will install the package config file in `/usr/lib/pkgconfig`. Some distributions, notably Fedora, will instead look for the library in `/usr/lib64`. Update your `PKG_CONFIG_PATH` environment variable with `/usr/lib/pkgconfig` and re-run Asterisk's `configure` script.

## Uninstalling a Previous Version of pjproject

Typically, other versions of pjproject will be installed as static libraries. These libraries are not compatible with Asterisk and can confuse the build process for Asterisk 12. As such, it is recommended that any static libraries be removed prior to installing the compatible version of pjproject.

pjproject provides an `uninstall` make target that will remove previous installations:

    make uninstall

Alternatively, the following should also remove all previously installed static libraries:

    rm -f /usr/lib/libpj*.a /usr/lib/libmilenage*.a /usr/lib/pkgconfig/libpjproject.pc

## Attachments:

image2993.png (image/png)
make-menuselect-pjsip.png (image/png)
make-menuselect-pjsip.png (image/png)
image2993.png (image/png)
make-menuselect-pjsip.png (image/png)