wiki:Getting_Started_Using

Version 2 (modified by bennylp, 18 years ago) (diff)

--

Building Application using PJSIP with GNU Tools

This article is a continuation of the Getting Started article as described in http://www.pjsip.org/using.htm.

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 http://www.pjsip.org/using.htm. 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. 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
    
    include $(PJBASE)/build.mak
    
    CC      = $(APP_CC)
    LDFLAGS = $(APP_LDFLAGS)
    LDLIBS  = $(APP_LDLIBS)
    CFLAGS  = $(APP_CFLAGS)
    CPPFLAGS= ${APP_CXXFLAGS}
    
    # 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. 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/tarani/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
    
  5. 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, and
    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.
  6. 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;
    }
    
  7. Last, run make in your source directory.