ios 在 Xcode 4.5 中使用 ZXing 库时架构 armv7 的未定义符号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12968369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:50:11  来源:igfitidea点击:

Undefined symbols for architecture armv7 when using ZXing library in Xcode 4.5

ioscocoa-touchios6zxingundefined-symbol

提问by Krishnabhadra

What I am trying to do

我想做什么

Integrate Zxing, QR code reader framework, in my iPhone project. I checked out ZXing sdk from here. I ran the sample project coming with ZXing, named ScanTest, without any issues. But when I try to integrate the library with my project I am getting the error mentioned.

在我的 iPhone 项目中集成Zxing,二维码阅读器框架。我从这里查看了 ZXing sdk 。我运行了 ZXing 附带的示例项目,名为 ScanTest,没有任何问题。但是当我尝试将库与我的项目集成时,我收到了提到的错误。

Project specification

项目说明

  • Target OS: iOS 6.0
  • Deployment target: iOS 5.0 or above.
  • Tested on: iPhone 4 and iPhone 3GS.
  • Xcode: Xcode 4.5.1
  • ZXing version: 2.0
  • 目标操作系统:iOS 6.0
  • 部署目标:iOS 5.0 或以上。
  • 测试:iPhone 4 和 iPhone 3GS。
  • Xcode: Xcode 4.5.1
  • ZXing版本:2.0

Problem

问题

When I build, after doing every integration step in ZXing readme file, I am getting build errors like

当我构建时,在ZXing 自述文件中完成每个集成步骤后,我收到构建错误,例如

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

There are 27 errors like that.. I only copied the first two.

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

What did I found out

我发现了什么

Well, I went through this, this,this,this, this, this,thisthreads in stackoverflow, all with the same error message. None of the solutions worked for me.

好吧,我在 stackoverflow 中经历了这个这个这个这个这个这个这个线程,所有的错误信息都是一样的。没有一个解决方案对我有用。

Then I found this closed threadin ZXing forums discussing the same issue. From that discussion, some possible solutions are (worked for some)

然后我在 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 重命名为 main.mm。第二个错误是(可能)因为您没有链接小部件库

I also renamed my main.m, cross checked whether I have added the library only to find I surely had. So this is not the case.

我还重命名了我的 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)”以匹配我的主项目后,我能够成功编译应用程序。

My project, target, library project (for debug, distribution, release) architecture is given as Standard (armv7, armv7s). So no luck there either.

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

Then they closed the issue saying this,

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

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.

zxing 项目已更新以添加 armv7s 架构并删除 armv6 架构。这些更改需要 (1) 为 iPhone 5 构建,也就是 armv7s 和 (2) 完全构建,因为 Xcode 4.5 不包括对 armv6 的支持。如果您有自己的项目文件,则需要自己进行这些更改。这些是不特定于 zxing 的一般更改,因此如果您遇到问题,可以在 StackOverflow 等通用论坛中获得更多/更快的帮助。

So here I am, in StackOverflow.

所以我在这里,在 StackOverflow 中。

One more point

多一点

In ZXing integration README file, the first step in integration is,

在 ZXing 集成README 文件中,集成的第一步是,

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"'.

1) 在“ ”下找到“ZXingWidget.xcodeproj”文件zxing/iphone/ZXingWidget/。将 ZXingWidget.xcodeproj 拖放到 Xcode 项目的“组和文件”侧栏的根目录上。将出现一个对话框——确保在单击“添加”之前未选中“复制项目”且“引用类型”为“相对于项目”。或者,您可以右键单击您的项目导航器并选择“将文件添加到“MyProject””。

When I dragged the ZXingWidget.xcodeproj file to my project, there was no dialog. The project directly added to the project and I could not set, "copy items" and "Reference Type" properties. I don't know if it is a new feature of Xcode 4.5 or a bug. That is the only step I couldn't correctly follow as per the README file.

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

Well, you have all the information that I have with me. I have been trying to fix this for 6 hours. Any idea?

好吧,你拥有我所拥有的所有信息。我一直试图解决这个问题 6 个小时。任何的想法?

回答by Krishnabhadra

Well, at last I got it working.. For anyone who encounters this in the future..

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

  1. Rename the main.m file to main.mm.

    ZXing's README states why we need this

    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. Rename the file (ViewController/View) which uses ZXing libray functions so that it also has .mm extension.

  3. Check architecturesettings across project. Give architectureand valid architectureas armv7 armv7sin your project settings, target settings, and ZXing project (which you added to your main project) and target settings.

  4. In main project-> Build Settingsscroll and find out the options, C++ Language Dialectand C++ Standard Library. Select options "Compiler Default"for both of them. (This is the step I missed, It is needed because newest XCode template has compiler default settings different to what they were in older versions).

  5. You also might have to set ZXingWidget's "Build Valid Architecture Only" flag set as NO. In my case, this field was already NO

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

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

    当尝试使用 ZXingWidgetController 构建您自己的项目时,可能会出现链接器错误,例如“未定义的引用”。如果这个错误看起来像一个 c++ 未定义的引用,那么将 main.m 重命名为 main.mm(Objective-C++ 源代码后缀)可能会解决这个问题

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

  3. 检查整个项目的架构设置。给 建筑有效的架构ARMv7的armv7s在您的项目设置,目标设置,以及斑马线项目(您添加到您的主项目)和目标设置。

  4. 在 main project-> Build Settings滚动并找出选项,C++ Language DialectC++ Standard Library。为它们选择选项“编译器默认”。(这是我错过的步骤,这是必需的,因为最新的 XCode 模板的编译器默认设置与旧版本不同)。

  5. 您可能还必须将 ZXingWidget 的“仅构建有效架构”标志设置为NO. 就我而言,这个领域已经NO

These fixed the issue for me..

这些解决了我的问题..

Update

更新

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

So developers are encouraged to move over to the native Apple framework to read barcodewhich is available from iOS7 onwards. See thisfor a step by step tutorial.

因此,我们鼓励开发人员转向原生 Apple 框架来读取iOS7 及以后可用的条码。有关分步教程,请参阅此内容

回答by Patrick Gibson

I've followed all of the suggestions above, and while everything compiles fine, the linking fails:

我遵循了上面的所有建议,虽然一切编译正常,但链接失败:

"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)
  zxing::GridSampler::checkAndNudgePoints(zxing::Ref<zxing::BitMatrix>, std::vector<float, std::allocator<float> >&) in libZXingWidget.a(GridSampler.o)
  zxing::qrcode::DecodedBitStreamParser::decodeNumericSegment(zxing::Ref<zxing::BitSource>, std::string&, int) in libZXingWidget.a(DecodedBitStreamParser-64E27B33E79CBC52.o)
  zxing::qrcode::Mode::forBits(int) in libZXingWidget.a(Mode.o)

... "std::ios_base::Init::Init()", referenced from:

...“std::ios_base::Init::Init()”,引用自:

  ___cxx_global_var_init in libZXingWidget.a(QRCodeReader-F470BE6889D3F76D.o)
  ___cxx_global_var_init in libZXingWidget.a(Decoder-3DF771F40A970F8E.o)
  ___cxx_global_var_init in libZXingWidget.a(FormatReader.o)
  ___cxx_global_var_init in libZXingWidget.a(QRCodeReader-C190599C861BFE46.o)
  ___cxx_global_var_init in libZXingWidget.a(DecodeHints.o)
  ___cxx_global_var_init in libZXingWidget.a(BinaryBitmap.o)
  ___cxx_global_var_init in libZXingWidget.a(DecoderResult.o)

and so on...

等等...

I'm running Xcode 4.5.2. I've renamed main.m to main.mm, my view controller was also renamed from .m to .mm, architecture everywhere is "armv7 armv7s".

我正在运行 Xcode 4.5.2。我已将 main.m 重命名为 main.mm,我的视图控制器也从 .m 重命名为 .mm,架构到处都是“armv7 armv7s”。

Sigh...

叹...

Update

更新

Someone on the Apple devforums had the answer to my problem:

Apple devforums 上有人回答了我的问题:

It looks like you have mismatched C++ standard libraries. Your project's build settings are using clang's C++ standard library, but libZXingWidget.a was compiled to use the GNU C++ standard library.

Try this: open ZXingWidget.xcodeproj and set the "C++ Standard Library" to "libc++", then Clean everything and rebuild.

If that doesn't work, try setting "C++ Standard Library" to "libstdc++" in both your project and ZXingWidget.xcodeproj

看起来您的 C++ 标准库不匹配。您的项目的构建设置使用 clang 的 C++ 标准库,但 libZXingWidget.a 被编译为使用 GNU C++ 标准库。

试试这个:打开 ZXingWidget.xcodeproj 并将“C++ 标准库”设置为“libc++”,然后清理所有内容并重建。

如果这不起作用,请尝试在您的项目和 ZXingWidget.xcodeproj 中将“C++ 标准库”设置为“libstdc++”

The first suggestion did the trick.

第一个建议成功了。

回答by jimbob

I solved it by changing one value on the project you dragged and dropped in to xcode.

我通过更改您拖放到 xcode 的项目上的一个值来解决它。

enter image description here

在此处输入图片说明

Set:

放:

Build Active Architecture Only -> Debug -> No

仅构建活动架构 -> 调试 -> 否

Hope that helps people :)!

希望可以帮助人们:)!

回答by RawMean

This solved the problem for me. Nothing else worked.

这为我解决了这个问题。没有其他工作。

enter image description here

在此处输入图片说明

回答by diadyne

It may also be necessary to set the ZXingWidget target's "Build Active Architecture Only" flag to "NO".

可能还需要将 ZXingWidget 目标的“仅构建活动架构”标志设置为“否”。

回答by riven

I've followed all of the suggestions above, and while everything compiles fine, but still fail, the error message:

我已经遵循了上面的所有建议,虽然一切编译正常,但仍然失败,错误消息:

Undefined symbols for architecture armv7:
"_CVPixelBufferLockBaseAddress", referenced from:-[ZXingWidgetController captureOutput:didOutputSampleBuffer:fromConnection:] in libZXingWidget.a(ZXingWidgetController.o)
"_CVPixelBufferGetBytesPerRow", referenced from:-[ZXingWidgetController captureOutput:didOutputSampleBuffer:fromConnection:] in libZXingWidget.a(ZXingWidgetController.o)
"_CVPixelBufferGetWidth", referenced from:-[ZXingWidgetController captureOutput:didOutputSampleBuffer:fromConnection:] in libZXingWidget.a(ZXingWidgetController.o)
"_CVPixelBufferGetBaseAddress", referenced from:-[ZXingWidgetController captureOutput:didOutputSampleBuffer:fromConnection:] in libZXingWidget.a(ZXingWidgetController.o)
"_kCVPixelBufferPixelFormatTypeKey", referenced from:-[ZXingWidgetController initCapture] in libZXingWidget.a(ZXingWidgetController.o)
"_CVPixelBufferGetHeight", referenced from:-[ZXingWidgetController captureOutput:didOutputSampleBuffer:fromConnection:] in libZXingWidget.a(ZXingWidgetController.o)
"_CVPixelBufferUnlockBaseAddress", referenced from:-[ZXingWidgetController captureOutput:didOutputSampleBuffer:fromConnection:] in libZXingWidget.a(ZXingWidgetController.o)ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

so, you add CoreVideo.framework, the compile will be ok.

所以,你添加CoreVideo.framework,编译就可以了。

回答by stackdaddy

I went over everything multiple times and after countless tried it turns out I just needed to Clean my project. This was necessary after changing the C++ Language Dialect and C++ Standard Library to Compiler Default. Something simple I do all the time but I missed it and wasted 30 minutes.

我多次检查所有内容,经过无数次尝试,结果证明我只需要清理我的项目。在将 C++ 语言方言和 C++ 标准库更改为编译器默认值后,这是必要的。我一直在做一些简单的事情,但我错过了,浪费了 30 分钟。