简体   繁体   中英

Linker Error in Xcode 5 for libzbar.a

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 "

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!)

第1步:编辑方案

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)

第2步:配置架构

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.

第3步:配置部署目标

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.

我通过将“Build Active Architecture Only”更改为YES来避开错误,不仅仅用于Debug,还用于Release ...至少现在,这节省了我。

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM