Skip to content

Xcode 4 with External Static Library for iPhone Development

521xcodeI upgraded to the latest Xcode 4 and had a tough time using it as things have changed quite a bit. (I’m not too familiar with Xcode 3 either so that didn’t help.) I also needed to make and include a static library (Live555) for the iPhone application that I am building. Because Xcode 4 is so new, there weren’t a lot of resources out on the internet. I finally got my app working with the static library and wanted to post some hints here. Hopefully this post will help those who are also having problems getting up to speed with Xcode 4.

Adding a Framework or Static Library File (with .a extension)

  1. Click on the folder icon under the giant top-left Run icon to “Show the Project navigator”
  2. Click on the Project name right underneath
  3. Click on the project name under “TARGETS”
  4. Click on “Build Phases” and then open up “Link Binary With Libraries” section
  5. Click on the plus button to add a Framework such as “AVFoundation.framework”.
    • If you want to add an external library, click on “Add Other…” and find your library file
  6. Doing the above will update the “Library Search Paths” setting automatically with the path to your library file. You can see what was set by doing the following:
    • Click on “Build Settings” (right before “Build Phases”)
    • Expand “Search Paths” and you should see “Library Search Paths”
  7. Most likely, you will need to use corresponding header files for your library file. To get this to work, you must add the header include path to “Header Search Paths” (if you use: #include <header.h>) and/or “User Header Search Paths” (if you use: #include “header.h”). Alternatively, if you set “Always Search User Paths” (also under “Search Paths” section) to “Yes”, then you just need to set “User Header Search Paths” for both include methods to work.
    • Click on “Build Settings” (right before “Build Phases”)
    • Click on “All” and scroll down to “Search Paths”
    • Double-click on the blank entry area to the right of “Header Search Paths” and/or “User Header Search Paths” to open up a dialog window.
      • Click the plus button and a checkbox will be added under “Recursive”. You can check the “Recursive” checkbox if you want Xcode to look into subdirectories also.
      • Double-click in the entry area to the right of the newly-added checkbox and input the path
    • You can then click on “Basic” and now “Header Search Paths” and/or “User Header Search Paths” will appear since they are no longer empty.

Building with an External Static Library File

  • The Xcode 4 SDK has been updated so make sure to update the sysroot directory in your Makefile to be “/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk”.
  • When compiling the library, if you see this error “ld: file not found: /usr/lib/system/libcache.dylib for architecture armv7”, then your linker command is using “–sysroot” which doesn’t work in Xcode 4. Instead, change the linker command to use “-isysroot”. (Note: This only applies to the linker command. The compile commands must continue to use “–sysroot”. See here for more details.)
  • When building the Xcode project with your library, if you see this error “file was built for archive which is not the architecture being linked (armv6)”, then the library you are linking to does not support armv6. In my case, I built the library using the “-arch armv7” so the resulting library did not support armv6. (I haven’t figured out how to compile a library for both armv6 and armv7 yet.) I had to force Xcode 4 to build only for armv7 to solve this error:
    1. Show the Project navigator
    2. Click on the Project name right underneath
    3. Click on the project name under “PROJECT”
    4. Expand the “Architectures” section (first section) and select “Optimized (armv7)” for the “Architectures” setting. (The default setting was “Standard (armv6 armv7)”.)

Using the Integrated (nice!) Interface Builder

  1. Show the Project navigator and click once on the project’s MainWindow.xib or Controller.xib file. The MainWindow.xib is the parent of the Controller.xib. You will want to put your UI components into Controller.xib.
  2. The Interface Builder will appear in the right content area.
  3. Show the utility pane by going to menu “View->Utilities->Show Utilities”. This pane is very useful and I leave it open all the time.
  4. To add a class which has UI hooks (IBOutlet and IBAction) to the Interface Builder:
    • Click on Controller.xib to show the Interface Builder. (Go ahead and add your buttons, text fields, sliders, etc., if you haven’t already done so.)
    • Go to menu “View->Utilities->Object Library”.
    • In the bottom-right of the Utilities pane, scroll down to “Object” and drag-n-drop it onto the Interface Builder content area. The Object will appear on the Interface Builder’s left vertical dock.
  5. Tie the IBOutlets/IBActions to the UI Components:
    • Select the Object in the dock and go to menu “View->Utilities->Identity Inspector”.
    • At the top of the Utilities pane, under the “Custom Class” section, hit the drop down to change “NSObject” to your custom class.
    • Leave the Object in the dock selected and go to menu “View->Utilities->Connections Inspector”.
    • At the top of the Utilities pane, click on the circle to the right of your Outlet or Receive Action and drag to the UI component you want to attach to. For Receive Action, you will be prompted to select the action, such as “Touch Down”.
  6. If you have added IBOutlet/IBAction hooks to your Controller class, do not add a custom Object to Controller.xib and change it to be your Controller class. Instead, use the pre-defined “File Owner” object in Controller.xib which is your Controller class. If you use your own custom Object instead of “File Owner” object, your iPhone application may crash.

Compiling the Live555 Streaming Media Library

For those interested, I had to make the following changes to compile the Live555 Streaming Media Library. Before running “./genMakefiles iphoneos”, update these two files:

  • Update the “config.iphoneos” file by adding one line to create a common variable, SYSROOT_DIR, and updating the compile and linker commands to use it:
    SYSROOT_DIR = /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk
    COMPILE_OPTS = $(INCLUDES) -I. $(EXTRA_LDFLAGS) -DBSD=1 -O2 -DSOCKLEN_T=socklen_t -DHAVE_SOCKADDR_LEN=1 -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -fPIC -arch armv7 --sysroot=$(SYSROOT_DIR)
    LINK_OPTS = -L. -arch armv7 -isysroot=$(SYSROOT_DIR)
  • Compiling the Live555 test executable programs would cause linker errors. To avoid these errors, update the “Makefile.tail” by commenting out these lines with the # character:
    #TESTPROGS_DIR = testProgs
    #MEDIA_SERVER_DIR = mediaServer

    all:
    ...
    #       cd $(TESTPROGS_DIR) ; $(MAKE)
    #       cd $(MEDIA_SERVER_DIR) ; $(MAKE)

    clean:
    ...
    #       cd $(TESTPROGS_DIR) ; $(MAKE) clean
    #       cd $(MEDIA_SERVER_DIR) ; $(MAKE) clean

Good luck with your iPhone development!

16 Comments

  1. Thanks for the tips on building the Live555 library. Very very helpful.

  2. newuser

    I tried the steps to add a external library file (.a), but always report “***.h” file not found when using “#import “***.h”, any suggestion?

    Many Thanks,

    • Chanh

      Take a look at step #7 under the first “Adding a Framework or Static Library File (with .a extension)” section above. It sounds like you need to add the directory where the library’s header files are located to the “User Header Search Paths” in the Xcode project’s build settings.

  3. Vimal Jain

    Thanks for the tips. It become very useful for me.

  4. Irit

    Thank you – I also just started with Xcode and was struggling to figure out where the basic settings are. (I gave up on finding the docs 🙂

  5. tamerlan

    I cannot find live555 framework
    Which path i must add to the “User Header Search Paths”?

    • Chanh

      You will want to add the .hh header files from the live555 components that you are trying to use. For example, in the live555 distribution, the header files are located at ../BasicUsageEnvironment/include, ../groupsock/include, ../liveMedia/include, ../UsageEnvironment/include, etc.

  6. tamerlan

    Thank you!
    One more question. Can i use live555 and play in my ios app. live stream like this one http://93.100.195.132:8013?

  7. Geoff

    Thanks!

    BTW, I believe you can create a universal static library, by using the lipo command to combine libraries compiled for different architectures.

    e.g.:
    lipo -arch armv6 lib/armv6/libexamplelib.a -arch armv7 lib/armv7/libexamplelib.a -create -output lib/libexamplelib.a

  8. I’m currently trying to integrate live555 in my iOS application. I’m not able to make it work. Can someone help me ?

    Thank you

    • Chanh

      Hi William, could you provide some specifics on what you might need help with? For example, if you are getting a compilation error, what is that error? Regards.

  9. My main issue is : I don’t know how to integrate the library in my project and use it. I’ve followed the steps above. I’ve tried to drag and drop the library into my project my I’m not able to use it. If you can show me what are the steps, that will be grateful.

    Thank you for your help, I’m disheartened

    • Chanh

      It’s been a while since I looked at it so the following might not be 100% complete.

      In your live555 directory, after the make, you will see the following four library files with .a extension: liveMedia/libliveMedia.a, groupsock/libgroupsock.a, UsageEnvironment/libUsageEnvironment.a, and BasicUsageEnvironment/libBasicUsageEnvironment.a.

      Run Xcode, right-click on the project’s main directory, and select “Add files to …” menu item. Then browse to each of the library files above and add them. All four files will then show up right underneath the main project folder. In your Xcode source file where you wish to make use of the live555 objects, include the following live555 header files like so:

      #include “liveMedia.hh”
      #include “BasicUsageEnvironment.hh”
      #include “GroupSockHelper.hh”

      class MyMediaSink : public MediaSink(

      Hopefully the above will fix the “Unknown type name ‘class’; did you mean ‘Class’” error.

  10. I manage to compile the library for iOS.
    But I’m getting this error

    Unknown type name ‘class’; did you mean ‘Class’?

  11. Dilip

    could this live555 library still used to stream RTSP and MMS URLs. I have tried so many project from GITHub and does not get successful result could you provide some code for that.mail would be better.

    • Chanh

      Hi Dilip,

      I did managed to get a prototype of video downstreaming using the Live555 RTSP/RTP library to work on the iphone. I used a test server that sent JPEG images so as to avoid dealing with the decoding. However, the framerate was atrocious (like 5 per second) because I didn’t know how to optimize video rendering on the iphone (I used the basic OpenGL library for rendering). I’m afraid that the test code was lost when my macbook’s hard drive crashed and I didn’t have a backup.

      On the Android, I successfully compiled and ran the Android VLC player to download and play RTSP/RTP streams from the Internet. The VLC codebase is complex and makes use of subsets from many libraries, including Live555. And the VLC code is doing some special video rendering optimization on Android that I haven’t been able to figure out yet.

      It might be worth it for you to check out the source for the VLC media player for iOS to see how it is using the Live555 library. That’s what I would do.

      Good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *