8
votes

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 "

4
Select "the project file" and goto "Build Phases" --> select the "Compiled sources" then Check ZBarReaderViewController.m is present or not ? If not there means press + sign and add the fileArun
@Spynet Can you please explain in brief?Pankti Patel
@Spynet , Thank you for reply. But as i use Zbar Sdk , there is no .m files available.Pankti Patel
Select "the project file" and goto "Build Phases" --> select the "Linked binaries" then check libzbar.a is available or not ?Arun
@PanktiPatel you should mark mario's answer as correct.MrTristan

4 Answers

40
votes

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.

2
votes

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.

1
votes

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.

-2
votes

ZBarSDK-1.3.1 BETA fixs the problem without rebuilding.

Just download ZBarSDK-1.3.1.dmg image, remove the ZBarSDK folder from your project and replace it with the last one: http://sourceforge.net/projects/zbar/files/iPhoneSDK/beta/