gpt4 book ai didi

ios - 在 Xcode 4.5 中使用 ZXing 库时架构 armv7 的 undefined symbol

转载 作者:IT王子 更新时间:2023-10-29 07:41:58 26 4
gpt4 key购买 nike

我想做什么

整合Zxing ,二维码阅读器框架,在我的 iPhone 项目中。我从 here 查看了 ZXing sdk。 .我运行了 ZXing 附带的名为 ScanTest 的示例项目,没有任何问题。但是,当我尝试将该库与我的项目集成时,出现了上述错误。

项目说明

  • 目标操作系统:iOS 6.0
  • 部署目标:iOS 5.0或以上。
  • 测试:iPhone 4 和 iPhone 3GS。
  • Xcode : Xcode 4.5.1
  • ZXing版本:2.0

问题

当我构建时,在 ZXing readme file 中完成每个集成步骤之后,我收到类似

的构建错误
Undefined symbols for architecture armv7:
"std::basic_ostream<char, std::char_traits<char> >& std::operator<<<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
zxing::qrcode::Detector::computeDimension(zxing::Ref<zxing::ResultPoint>, zxing::Ref<zxing::ResultPoint>, zxing::Ref<zxing::ResultPoint>, float) in libZXingWidget.a(Detector-B8B28E953F840D47.o)

Undefined symbols for architecture armv7:
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
zxing::Exception::Exception(char const*) in libZXingWidget.a(Exception.o)
zxing::common::StringUtils::guessEncoding(unsigned char*, int, std::map<unsigned int, std::string, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, std::string> > >

这样的错误有 27 个。我只复制了前两个。

我发现了什么

好吧,我经历了this , this , this , this , this , this , this stackoverflow 中的线程,都具有相同的错误消息。没有一种解决方案对我有用。

然后我找到this closed thread在 ZXing 论坛讨论同样的问题。从那次讨论中,一些可能的解决方案是(对某些人有效)

The first error is (probably) because you haven't renamed main.m to main.mm. The second error is (probably) because you're not linking against the widget library

我还重命名了我的 main.m,交叉检查我是否添加了库才发现我肯定有。所以事实并非如此。

After I changed the Architectures of the library to "Standard (armv7, armv7s)" to match my main project I was able to successfully compile the app.

我的项目、目标、库项目(用于调试、分发、发布)架构为标准(armv7、armv7s)。所以那里也没有运气。

然后他们关闭了这个问题,

The zxing projects have been updated to add the armv7s arch and remove the armv6 arch. These changes are required (1) to build for the iPhone 5 which is armv7s and (2) to build at all since Xcode 4.5 does not include support for armv6. If you have your own project files, you'll need to make these changes yourself. These are general changes not specific to zxing so if you have trouble, you make get more/quicker help in a general forum like StackOverflow.

所以我在 StackOverflow 中。

还有一点

在ZXing集成中README file ,整合的第一步是,

1) Locate the "ZXingWidget.xcodeproj" file under "zxing/iphone/ZXingWidget/". Drag ZXingWidget.xcodeproj and drop it onto the root of your Xcode project's "Groups and Files" sidebar. A dialog will appear -- make sure "Copy items" is unchecked and "Reference Type" is "Relative to Project" before clicking "Add". Alternatively you can right-click on you project navigator and select 'Add files to "MyProject"'.

当我将 ZXingWidget.xcodeproj 文件拖到我的项目中时,没有对话框。该项目直接添加到项目中,我无法设置“复制项目”和“引用类型”属性。不知道是Xcode 4.5的新特性还是bug。根据 README 文件,这是我无法正确遵循的唯一步骤。

嗯,你有我所有的信息。我一直在尝试修复此问题 6 个小时。有什么想法吗?

最佳答案

好吧,最后我让它工作了..对于将来遇到这种情况的任何人..

  1. 将 main.m 文件重命名为 main.mm。

    ZXing 的 README 说明了我们为什么需要这个

    It can happen that when trying to build your own project with ZXingWidgetController you get linker errors like "undefined reference to". If this error looks like a c++ undefined reference, then renaming main.m into main.mm (Objective-C++ source suffix) may fix the problem

  2. 重命名使用 ZXing 库的文件 (ViewController/View)功能,使其也具有 .mm 扩展名。

  3. 检查整个项目的架构设置。给architecturevalid architecture 作为 armv7 armv7s 在你的项目设置、目标设置和 ZXing 项目(你添加到您的主项目)和目标设置。

  4. 在主 project -> Build Settings 滚动并找出选项、C++ 语言方言C++ 标准库。为它们选择选项 “Compiler Default”。 (这是我错过的步骤,这是必需的,因为最新的 XCode 模板有编译器默认设置与旧版本不同版本)。

  5. 您可能还必须设置 ZXingWidget 的“Build Valid ArchitectureOnly”标志设置为NO。在我的例子中,这个字段已经是NO

这些解决了我的问题..

更新

2013 年 12 月, Google has retired ZXing iOS/Objective C端口。因此,iOS 的 Zxing 项目不再针对新的 iOS 版本进行维护和更新。此外,Zxing 不支持 Arm64 架构,这是新 XCode 版本的标准架构之一。

因此鼓励开发人员转移到 native Apple framework to read barcode从 iOS7 开始可用。参见 this获取分步教程。

关于ios - 在 Xcode 4.5 中使用 ZXing 库时架构 armv7 的 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12968369/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com