Xcode 5 中 libzbar.a 的链接器错误 [英] Linker Error in Xcode 5 for libzbar.a

查看:23
本文介绍了Xcode 5 中 libzbar.a 的链接器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我将 ZBar Sdk 集成到我的项目中后,我的 xcode 5-DP 开始显示以下警告:

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

"ld: 警告:为 iOS 模拟器链接 ObjC,但目标文件 (/Documents/Projects/Project/Utility/ZBarSDK/libzbar.a(ZBarReaderViewController.o)) 是为 MacOSX 编译的"

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

推荐答案

构建 ZBar 库

前段时间我在 ZBar 上遇到了不同的问题,并在此处获得了一组有用的说明:https://web.archive.org/web/20170128181158/http://www.federicocappelli.net/2012/10/05/zbar-library-for-iphone-5-armv7s/

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/

基本上,这些说明会告诉您如何使用 Mercurial 查看源代码,然后编译您自己的 libzbar.a 文件.这应该可以解决您的问题.

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.

事实上,就在昨晚,我不得不再次按照说明进行操作,因为我的 ZBar 版本在更新到 Xcode 5 后无法运行.我鼓励您按照上面的链接进行操作,但我要主要在这里,以及我为新 iPhone 平台添加的一些步骤.

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.

下载 并安装 Mac 版 Mercurial.我为 OS X 10.8 选择了最新的.(安装屏幕,当您启动安装程序时,似乎仍然显示 10.7,所以不要感到惊讶.)

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

安装 Mercurial 后,使用以下命令下载 ZBar 的源代码:

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 

在 Xcode 的菜单中,选择Product > Scheme > libzbar",然后选择Product > Scheme > Edit Scheme...".(您会收到一条警报,告诉您项目已更新为使用 LLBD 调试器.是的!)

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

在构建配置中选择运行"并单击确定".

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

接下来,我们将为设备和模拟器编译 libzbar.在 Project and Targets 列表中,选择 libzbar 目标并单击 Build Settings 选项卡.验证您的架构设置,如屏幕截图所示.(确保它显示 iOS 和 arm64 armv7 armv7s.)

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

另外,不要忘记将 Architectures 更改为标准架构(armv7、armv7s、arm64),否则您的项目将无法使用 arm64 进行编译.(这在屏幕截图上没有正确显示)

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)

现在,这是我昨晚发现的部分.我的部署目标设置为 iOS 3.1.如果您尝试使用该设置在 Xcode 5 中进行编译,则会出现错误.我将其更改为 iOS 7.0.

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.

在验证您的设置并根据需要更改任何设置后,运行 Build.返回Product > Scheme > Edit Scheme…"并检查Destination"下拉菜单.(请参阅上面的屏幕截图.)我在 iPhone Retina(3.5 英寸)上安装了我的屏幕.将其更改为 iOS 设备并再次运行 Build.您现在已经构建了两次库:一次用于模拟器,一次用于设备.您需要组合这两个库.转到终端中的以下目录:

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

里面有一堆名字很神秘的目录,其中一个以zbar"开头.这是我的完整路径,例如:

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

进入那个 zbar 目录,然后进入 Build/Products 目录.

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

    cd Build
    cd Products

在那里您将看到两个文件夹:Release-iphoneos 和 Release-iphonesimulator.(每个里面都有一个 lizbar.a 文件.)用下面的命令将它们组合起来:

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 

您现在已经创建了一个您应该使用的通用库 (libzbar.a),替换了您的 ZBar 发行版附带的库.它位于同一个 Build/Product 目录中.

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.

正如我所说,我很大程度上抄袭了上述链接作者 Cappelli 先生的说明,并针对最新的 Xcode 进行了更新.

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.

这篇关于Xcode 5 中 libzbar.a 的链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆