wiki:Getting_Started_Using
Last modified 7 years ago Last modified on 01/15/10 09:57:16

Building Application using PJSIP with GNU Tools

  1. Requirements
  2. Steps for Building Your Application that Uses PJSIP/PJMEDIA
  3. Having Any Problems?
  4. Credits

Requirements

  • GNU tools (GNU make, binutils, gcc, and the likes).

Steps for Building Your Application that Uses PJSIP/PJMEDIA

  1. First, build pjproject libraries as described in building for GNU systems. This normally is accomplished by executing these commands: $ ./configure && make dep && make
  2. Create a directory outside the PJSIP sources for your project and place your source files there.
  3. Create a file named Makefile in your source directory:
    1. If you have PJ version 1.6 or later, and you run make install, and you have pkg-config tool, you can use this template for your Makefile:
      # If your application is in a file named myapp.cpp or myapp.c
      # this is the line you will need to build the binary.
      all: myapp
      
      myapp: myapp.cpp
              $(CC) -o $@ $< `pkg-config --cflags --libs libpjproject`
      
      clean:
              rm -f myapp.o myapp
      
    2. Otherwise if you have PJ version 0.5.10.2 or later, you can use this template for your Makefile:
      #Modify this to point to the PJSIP location.
      PJBASE=/home/myself/pjproject-0.5.10.2
      
      include $(PJBASE)/build.mak
      
      CC      = $(PJ_CC)
      LDFLAGS = $(PJ_LDFLAGS)
      LDLIBS  = $(PJ_LDLIBS)
      CFLAGS  = $(PJ_CFLAGS)
      CPPFLAGS= ${CFLAGS}
      
      # If your application is in a file named myapp.cpp or myapp.c
      # this is the line you will need to build the binary.
      all: myapp
      
      myapp: myapp.cpp
              $(CC) -o $@ $< $(CPPFLAGS) $(LDFLAGS) $(LDLIBS)
      
      clean:
              rm -f myapp.o myapp
      
    3. Otherwise if you have PJ version 0.5.10.1 or older, you can use this template for your Makefile:
      # Modify this to point to the PJSIP location.
      PJBASE=/home/myself/pjproject-0.5.10.1
      
      include $(PJBASE)/build/mak
      
      CC=$(CROSS_COMPILE)$(CC_NAME)
      
      # Remove components that you don't need from the following definitions.
      LDFLAGS=-L${PJBASE}/pjlib/lib\
          -L${PJBASE}/pjlib-util/lib\
          -L${PJBASE}/pjmedia/lib\
          -L${PJBASE}/pjsip/lib
      LDLIBS=-lpjsua-${TARGET_NAME}\
          -lpjsip-ua-${TARGET_NAME}\
          -lpjsip-simple-${TARGET_NAME}\
          -lpjsip-${TARGET_NAME}\
          -lpjmedia-codec-${TARGET_NAME}\
          -lpjmedia-${TARGET_NAME}\
          -lpjmedia-codec-${TARGET_NAME}\
          -lpjlib-util-${TARGET_NAME}\
          -lpj-${TARGET_NAME}\
      	-lm\
      	-lpthread\
      	-lasound\
      	-lssl
      CFLAGS=-I${PJBASE}/pjlib/include\
          -I${PJBASE}/pjlib-util/include\
          -I${PJBASE}/pjmedia/include\
          -I${PJBASE}/pjsip/include\
          -DPJ_AUTOCONF=1
      CPPFLAGS=${CFLAGS}
      
      # If your application is in a file named myapp.cpp or myapp.c
      # this is the line you will need to build the binary.
      all: myapp
      
      myapp: myapp.cpp
              $(CC) -o $@ $< $(CPPFLAGS) $(LDFLAGS) $(LDLIBS)
      
      clean:
              rm -f myapp.o myapp
      
  4. There few things to note when making the Makefile above:
    1. First, make sure that you replace PJBASE with the location of PJSIP sources in your computer.
    2. If you notice there are spaces towards the bottom of the file (before $(CC) and rm, these are a single tab, not spaces. This is important, or otherwise make command will fail with "missing separator" error.
    3. Change myapp.cpp to your source filename.
    4. If you're using version 0.5.10.1 or older, then you may encounter link error with -lasound or -lssl. You may remove this from your Makefile (this is the limitation of 0.5.10.1 build system, which has been fixed in 0.5.10.2).
  5. Create myapp.cpp in the same directory as your Makefile. At minimum, it may look like this:
    #include <pjlib.h>
    #include <pjlib-util.h>
    #include <pjmedia.h>
    #include <pjmedia-codec.h>
    #include <pjsip.h>
    #include <pjsip_simple.h>
    #include <pjsip_ua.h>
    #include <pjsua-lib/pjsua.h>
    
    int main()
    {
            return 0;
    }
    
  6. Last, run make in your source directory.

Having Any Problems?

If you're having any problems or encounter some errors with above instructions, first please watch carefully the error messages that are printed to the screen. The error messages printed by the gcc or make normally should contain useful information about the error and how to fix it.

If you like more help, you can report the error to PJSIP mailing list. Don't forget to include the details of the error (such as copy/paste the compiler command and error output), because without this we simply wouldn't know how to help!

Credits

Thanks Binu KS <binuks -at- gmail dot com> for the initial tutorial in the PJSIP mailing list.