Linker Error in Xcode 5 for libzbar.a

10,662

Solution 1

Building a ZBar library

Sometime back I had a different problem with ZBar and was led to a helpful set of instructions here: https://web.archive.org/web/20170128181158/http://www.federicocappelli.net/2012/10/05/zbar-library-for-iphone-5-armv7s/

Basically, the instructions tell you how to check out the source code using Mercurial, and then compile your own libzbar.a file. This ought to solve your problem.

Just last night, in fact, I ended up having to follow the instructions again, because my version of ZBar wouldn't run after updating to Xcode 5. I encourage you to follow the link above, but I'm going to largely crib it here, along with some steps I've added for the new iPhone platform.

Download and install Mercurial for Mac. I took the latest one for OS X 10.8. (The installation screen, when you launch the installer, seems to still say 10.7, so don't be surprised.)

After installing Mercurial, download the source for ZBar with the following commands:

    hg clone http://zbar.hg.sourceforge.net:8000/hgroot/zbar/zbar 
    cd zbar 
    hg checkout iPhoneSDK-1.3.1 
    open iphone/zbar.xcodeproj 

In Xcode's menu, select "Product > Scheme > libzbar" and then select "Product > Scheme > Edit Scheme…". (You'll get an alert telling you the project has been updated to use the LLBD debugger. Yay!)

Step 1: Edit Scheme

Select "Run" in the build configuration and click OK.

Next, we're going to compile libzbar for both the device and the simulator. In the Project and Targets list, select the libzbar target and click on the Build Settings tab. Verify your Architecture settings, as shown in the screenshot. (Make sure it says iOS and arm64 armv7 armv7s.)

Also, don't forget to change Architectures to Standard architectures (armv7, armv7s, arm64), otherwise your project won't compile with arm64. (This is not shown properly on screenshot)

Step 2: Configure Architecture

Now, here is the part I discovered last night. My Deployment Target was set to iOS 3.1. You'll get an error if you try compiling in Xcode 5 with that setting. I changed it to iOS 7.0.

Step 3: Configure Deployment Target

After verifying your settings and changing any as needed, run Build. Go back to "Product > Scheme > Edit Scheme…" and check the "Destination" drop-down menu. (See the screenshot above.) I had mine on iPhone Retina (3.5-inch). Change it to iOS Device and run Build a second time. You have now built the library twice: once for the simulator and once for the device. You'll need to combine the two libraries. Go to the following directory in Terminal:

    cd ~/Library/Developer/Xcode/DerivedData

In there are a bunch of cryptically named directories, one of which will begin "zbar". Here's my full path, as an example:

    /Users/mario/Library/Developer/Xcode/DerivedData/zbar-dwpkaidpztsnjafveraeowkkjvdo

Go into that zbar directory, and then change into the Build/Products directory.

    cd Build
    cd Products

There you will see two folders: Release-iphoneos and Release-iphonesimulator. (Inside each is a lizbar.a file.) Combine them with the following command:

    lipo -create Release-iphoneos/libzbar.a Release-iphonesimulator/libzbar.a -o libzbar.a 

You have now created a universal library (libzbar.a) that you should use, replacing the one that came with your ZBar distribution. It is located in the same Build/Product directory.

As I've said, I have largely cribbed the instructions from the author of the link above, Mr. Cappelli, updating them for the latest Xcode.

Solution 2

Since Dec 2014, there is an easier solution than Mario's answer. Use CocoaPods and add this line to your Podfile:

pod 'ZBarSDK', '~> 1.3.1'

Then, run the classic pod install. It will build fine, including for arm64.

Solution 3

I skirted the error by changing the "Build Active Architecture Only" to YES, not only for Debug but for Release too... At least for now, this saved me.

Share:
10,662
Pankti Patel
Author by

Pankti Patel

Updated on July 26, 2022

Comments

  • Pankti Patel
    Pankti Patel almost 2 years

    After I integrate ZBar Sdk into my project, my xcode 5-DP starts showing below warning:

    "ld: warning: linking ObjC for iOS Simulator, but object file (/Documents/Projects/Project/Utility/ZBarSDK/libzbar.a(ZBarReaderViewController.o)) was compiled for MacOSX "

  • LJ Wilson
    LJ Wilson over 10 years
    Fantastic writeup. Thx!
  • Pochi
    Pochi over 10 years
    Would selecting iOS 6 as the deployment target modify anything? Im not sure if it means that I need the iOS7 SDK to build it or that i can only use it in iOS7 devices.
  • MrTristan
    MrTristan over 10 years
    great job condensing things... one thing that made me nervous is compiling this library off of the latest version... i dont think i was on latest so i had to go through things and update the header files that are in my proj in addition to swapping out the compiled library.
  • Mario
    Mario over 10 years
    I had to make sure to use the updated header files as well, in my project. That's a very good point.
  • Nirav Dangi
    Nirav Dangi almost 9 years
    you really saved me.. :P
  • stackOverFlew
    stackOverFlew almost 9 years
    For me, xcode 6 was not seeing my ZBarSDK.h until I followed your steps with compiling the correct library. For me, in my derived data folder however, I did not get Release-iphoneos/libzbar.a but I got Debug-iphoneos/libzbar.a. I just compiled those two and added it back to the project as well as the headers from zbar 1.3.1. Is this okay to do>
  • Mario
    Mario almost 9 years
    I haven't developed for iOS in a little while, so I'm not up to speed with what the latest is. I think you should be fine, but you should try to figure out what happened. My guess is that someone has posted, somewhere, about building libraries on Xcode and this debug/release issue. Good luck!