Linker Error in Xcode 5 for libzbar.a
Asked Answered
A

4

8

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 "

Allsun answered 11/9, 2013 at 11:47 Comment(6)
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 filePinnatiped
@Spynet Can you please explain in brief?Allsun
@Spynet , Thank you for reply. But as i use Zbar Sdk , there is no .m files available.Allsun
Select "the project file" and goto "Build Phases" --> select the "Linked binaries" then check libzbar.a is available or not ?Pinnatiped
Have added , but no improvements found. Still got the warning!!!! Also i found that this warning i got only in xcode 5.Allsun
@PanktiPatel you should mark mario's answer as correct.Haemin
G
40

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.

Giantess answered 21/9, 2013 at 21:28 Comment(6)
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.Guido
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.Haemin
I had to make sure to use the updated header files as well, in my project. That's a very good point.Giantess
you really saved me.. :PPatrilineal
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>Essex
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!Giantess
S
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.

Spadiceous answered 18/3, 2018 at 16:43 Comment(0)
C
1

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.

Cornia answered 10/4, 2014 at 17:48 Comment(0)
P
-2

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/

Pifer answered 7/10, 2013 at 12:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.