Search code examples
c++iosobjective-cxcodeopenh264

How to link or add openh264 library on Objective C project using Xcode


I am working with Openh264 library. I worked before with this library in Linux environment. But I haven't found any working documentation to link openh264 library on Xcode.

I have tried other solutions to add .a or .so library files in Xcode like: i) How to import a C++ library into a Xcode Objective C project? ii) How to link or load shared libraries (.so) in Objective C?

But Unfortunately I failed each time. I got OpenH264 from this link: https://github.com/cisco/openh264 . I can execute demo encoder decoder project which is given by Openh264 library but I need help to link this library in my own project. Thanks in advance.


Solution

  • Here are the steps to integrate OpenH264 Library to any Xcode Project:

    1. Download or Clone OpenH264 Library from this link: https://github.com/cisco/openh264
    2. Create Xcode project selecting IOS Application, Objective C and other mandatory options.
    3. Place OpenH264 Library with all files and folders in project root directory. For example my IOS application is at directory /user/rajib/HelloApp/HelloApp.xcodeproj, and OpenH264 Library kept in /user/rajib/HelloApp/OpenH264Library .
    4. Now open terminal and enable root mode.
    5. Go to the directory where OpenH264Library was kept and make with following command: ->sudo make OS=ios ARCH=amrv7 install
    6. Now go to Project Build Setting and find Header Search Path attribute. Add following header paths in separate lines to that attribute. $(inherited), "$(SRCROOT)/OpenH264Library/codec/encoder/core/inc", "$(SRCROOT)/OpenH264Library/codec/processing/interface", "$(SRCROOT)/OpenH264Library/codec/common/inc", "$(SRCROOT)/OpenH264Library/codec/api/svc",
    7. Now we have to integrate 3 more Xcode Projects named common.xcodeproj, processing.xcodeproj, welsenc.xcodeproj inside our HelloApp project. All these .xcodeproj files will be found inside OpenH264Library. We have to find these .xcodeproj files with that name inside OpenH264Library and just drag and drop these files inside our HelloApp project.
    8. Now Go to Project Build Phase and find Target Dependencies attribute. Add welsenc, processing, common project from the work place.
    9. Try to build this project, then these 3 project will compile and execute and we will find 3 static library in our work place.
    10. Now go to project Build phase again and find Link Binary with Libraries attribute. Add libwelsenc.a, libprocessing.a, libcommon.a static libraries from the workplace.

    That's it... this is the procedure of building and linking openh264 library. Now you can easily call openh264 library functions. Here I am giving a simple working code of Encoder initialization calling OpenH264 library function.

    //Adding Header files
    #include "codec_api.h"
    #include "codec_def.h"
    
    //Calling OpenH264 Library function to initialize Encoder
    - (IBAction)EncoderTestBtn:(id)sender {
        NSLog(@"Inside EncoderTestBtn");
        ISVCEncoder *pEncoder = NULL;
        int iRet = -1;
        iRet = WelsCreateSVCEncoder(&pEncoder);
        if(iRet == 0)
        {
            NSLog(@"Rajib_Check: Encoder Initialization SUCCESSFUL");
        }
        else
        {
            NSLog(@"Rajib_Check: ERROR--> iRet returned with = %d", iRet);
        }
    
    }