IOS Pjsip Notes (i) compiling a static library supported by multiple platforms

Source: Internet
Author: User

Long time No blog, this is my new job after the first technical blog post it. Before entering the new company, there was a technical layer ready to go into the next iteration, but many things were unexpected, like I was interviewing as a C # programmer, and now I'm a full-time IOS developer. From C # to objective-c switch, or there are a lot of costs, plus this year, the introduction of Swift, the future to learn the road is long, in fact, the path of learning itself is long, should not be satisfied with a stage and specific areas. For me, the language of the switch, is already too common, learning a language is very easy to do, but, completely grasp it, but not easy, like to understand a stranger's temper. A bit far away, or into the topic of today!

Pjsip, if you do not know what it is, then you do not need to use it, there is no need to continue to read this article. Because of the need to use VOIP in the project, compared to the cost of using the SIP implementation is relatively small, in Android, Google built-in support for SIP, IOS is not so good luck, and then found the Pjsip, this is a pure C library, the implementation of the very beautiful. On the network for a long time, also did not find suitable for me this kind of entry-level tutorial, in my groping and efforts, finally made a point. Well, congratulations, you don't have to go the detour I've been through.

Let's start with a step-by:

First step: Download

First, to the official website to download the source code, it is recommended to download. tar.bz2 package, after downloading, find the corresponding directory, with tar or graphical operation to extract, here I use the command line to operate:

$ TAR-JXVF pjproject-2.2.1.tar.bz2

Step Two: Compiling

First, in the pjlib/include/pj/directory, create a config_site.h file, switch to the directory, with VI or touch a file:

$ cd pjlib/include/pj/$ VI config_site.h

According to the official documentation, the contents of our document are defined as follows:

Pj_config_iphone 1#include <pj/config_site_sample.h>

OK, save, switch back to the main directory (that is, the folder with Pjlib, Pjmedia, Pjnath, etc.), this time we can compile, and there is a premise, you have to install XCode Command line Tools (xcode–> Preferences–>downloads).

I386

First compile the static library of the emulator platform, and then execute the following three sentences in turn:

$ Export devpath=/applications/xcode.app/contents/developer/platforms/iphonesimulator.platform/developer$ ARCH=  cflags=ldflags=./configure-iphone$ make dep && do clean && make

OK, no problem, your emulator version of the static library is compiled, they exist in:

    • Pjlib/lib
    • Pjlib-util/lib
    • Pjmedia/lib
    • Pjnath/lib
    • Pjsip/lib
    • Third_party/lib

These are the static libraries that must be used in future SIP development, and currently the library only supports emulators (which can be viewed using the Lipo–info command, only supports i386), so we copy them out, and of course I have written a copy of the script for you:

#!/bin/bashpjlib_path= "./lib/$1/pjlib" pjlib_util_path= "./lib/$1/pjlib-util" pjmedia_path= "./lib/$1/pjmedia" Pjnath_path= "./lib/$1/pjnath" pjsip_path= "./lib/$1/pjsip" third_party= "./lib/$1/third_party" echo "Start coping to $ "Rm-rf $PJLIB _pathrm-rf $PJLIB _util_pathrm-rf $PJMEDIA _pathrm-rf $PJNATH _pathrm-rf $PJSIP _pathrm-rf $THIRD _partymkdi R-p $PJLIB _pathmkdir-p $PJLIB _util_pathmkdir-p $PJMEDIA _pathmkdir-p $PJNATH _pathmkdir-p $PJSIP _pathmkdir-p $THIRD _pa Rtycp-r./pjlib/lib/$PJLIB _pathcp-r./pjlib-util/lib/$PJLIB _util_pathcp-r./pjmedia/lib/$PJMEDIA _pathcp-r./pjnath /lib/$PJNATH _pathcp-r/pjsip/lib/$PJSIP _pathcp-r/third_party/lib/$THIRD _partyecho "Copy Done"

Save the script as copylibs.sh and store it in the home directory (you should know where the home directory is!). ), and then execute:

$./copylibs.sh i386

If the prompt permission is not enough, then use chmod 777 copylibs.sh to give the file the maximum access permissions, after execution, all the generated static libraries are copied to the home directory in the corresponding location in the Lib directory.

ARMv7

Below continue to compile the ARMV7 version of the library, close the first console, Note that it is all closed before entering , and then to the main directory to execute the following command:

$ Arch= '-arch armv7 './configure-iphone$ make dep && do clean && make$./copylibs.sh armv7
armv7s

Now compile the armv7s version of the library, this time without shutting down the console, and then execute the following command directly (there are reported errors, but it is a sample project compilation error, and static link library file does not matter):

$ Arch= '-arch armv7s './configure-iphone$ make dep && do clean && make$./copylibs.sh armv7s
Arm64

Finally, we finished compiling the ARM64 repository:

$ Arch= '-arch arm64 './configure-iphone$ make dep && do clean && make$./copylibs.sh arm64
Step three: Merge static link libraries

Well, now we need the library has been copied to the Lib directory, it should now be this:

Right, there's a mix.sh underneath, and of course, this is the script I wrote for you:

#!/bin/bashouput_path= "./mixed/" xlipo= "/applications/xcode.app/contents/developer/platforms/iphoneos.platform/ Developer/usr/bin/lipo "for  dir in Armv7/*do    lib_name=${dir##*/}    Lib_output=${ouput_path} $LIB _name    rm-rf $LIB _output    mkdir-p $LIB _output for    subdir on ${dir}/*    do        afile=${subdir##*/}        armv7_ File= "./armv7/$LIB _name/$AFILE"        armv7s_file= "./armv7s/$LIB _name/$AFILE"        arm64_file= "./arm64/$LIB _name /$AFILE "        i386_file="./i386/$LIB _name/$AFILE "        echo" Start mixing FILE: $AFILE "                ${xlipo}-arch armv7 $ Armv7_file-arch armv7s $ARMV 7s_file-arch arm64 $ARM 64_file-arch i386 $I 386_file-create-output ${lib_output}/$AFILE 
   donedoneecho "All mixed Done"

Save the above script to the Lib directory under Mix.sh, console, CD switch to the Lib directory, and then execute:

OK, now that everything is finished, in the Lib directory will be more than a mixed directory, the directory under which all the libraries are included in the appeal of various schema version information, you can use Lipo to verify the following:

Note that whether you are merging or viewing, you should use the Lipo,mac that comes with Xcode Lipo not supported.

If you feel that it is too troublesome to do it yourself, then there is a version that has been compiled for you, and it can be downloaded directly:

Https://github.com/chebur/pjsip

However, I still recommend you to do it again, you get out of it, use it more interesting, hehe ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.