在XCode 4.5中使用ZXing库时,架构armv7的未定义符号 [英] Undefined symbols for architecture armv7 when using ZXing library in XCode 4.5

查看:298
本文介绍了在XCode 4.5中使用ZXing库时,架构armv7的未定义符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做什么



整合 Zxing ,QR码阅读器框架,在我的iPhone项目。我从此处检出了ZXing sdk。我运行示例项目与ZXing,名为ScanTest,没有任何问题。但是当我尝试将库与我的项目集成时,我遇到了提到的错误。



项目规范




  • 目标操作系统:iOS 6.0

  • 部署目标:iOS 5.0或更高版本。

  • XCode :Xcode 4.5.1

  • ZXing版本:2.0



问题



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

 架构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 *),引用自:
zxing :: qrcode :: Detector :: computeDimension(zxing :: Ref
体系结构armv7的未定义符号:
std :: basic_string< char,std:< zxing :: ResultPoint> float,in libZXingWidget.a(Detector-B8B28E953F840D47.o) :char_traits< char>,std :: allocator< char>在libZXingWidget.a(Exception.o)中引用自:
zxing :: Exception :: Exception(char const *),并且引用了:: basic_string(char const *,std :: allocator< char> const&
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>>>



我发现了什么



好吧,我经历了 this 在stackoverflow线程,所有具有相同的错误消息。没有一个解决方案为我工作。



然后我找到这个关闭的线程在ZXing论坛讨论相同的问题。从这个讨论,一些可能的解决方案(工作的一些)


第一个错误是将main.m重命名为main.mm。第二个错误是(可能),因为您未将
与窗口小部件库相关联


重命名我的main.m,交叉检查我是否添加了库只找到我肯定有。所以这不是这样的。


在我将库的
架构更改为Standard(armv7,armv7s) b $ b主项目我能够成功编译应用程序。


我的项目,目标,库项目调试,分发,发布)体系结构以 Standard(armv7,armv7s) 提供。所以没有运气。



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


项目已更新以添加armv7s arch和删除armv6 arch。这些更改是必需的(1)为
iPhone 5是armv7s和(2)构建,因为Xcode 4.5的
不包括对armv6的支持。如果你有自己的项目文件,
,你需要自己做这些更改。这些是一般的变化
不是特定于zxing所以如果你有麻烦,你在一个一般的论坛,如StackOverflow得到
更多/更快的帮助。


< blockquote>

所以这里我是,在StackOverflow。



多一点



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


1)在 zxing / iphone / ZXingWidget / 下找到ZXingWidget.xcodeproj文件。拖动ZXingWidget.xcodeproj并将它
放到Xcode项目的Groups and Files边栏的根目录下。将出现一个
对话框 - 确保复制项目未选中,
参考类型为相对于项目,然后单击添加。
或者您可以右键单击项目导航器并选择
'将文件添加到MyProject'。


当我将ZXingWidget.xcodeproj文件拖到我的项目时,没有对话框。项目直接添加到项目,我无法设置,复制项目和参考类型属性。我不知道这是xcode 4.5的一个新功能或一个错误。这是唯一的步骤,我不能正确按照README文件。



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

解决方案

嗯,最后我得到它的工作..对于任何人在未来遇到这个。 p>


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



    ZXing README状态为什么我们需要这个


    可能会发生,当试图用ZXingWidgetController构建自己的项目时,未定义引用
    到。如果这个错误看起来像一个c ++未定义的引用,则将
    main.m重命名为main.mm(Objective-C ++源后缀)可能会修复该问题



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


  3. 检查项目中的架构设置。在项目设置,目标设置和ZXing项目中将
    架构有效架构作为 armv7 armv7s


  4. 在主要项目 - > 构建设置滚动并找出
    选项, C ++语言方言 C ++标准库
    选择两个选项编译器默认。 (这是
    步骤,我错过了,它是需要的,因为最新的XCode模板有
    编译器默认设置不同于他们在旧的
    版本)。


  5. 您也可能需要设置ZXingWidget的 Build Valid Architecture
    Only
    标志设置为 NO 。在我的示例中,此字段已经是 NO


更新


2013年12月,Google已停用ZXing iOS / Objective C端口。所以iOS的Zxing项目不再维护和更新为新的iOS版本。此外,Zxing不支持Arm64架构,这是根据新的XCode版本的标准架构之一。



因此,我们鼓励开发者转移到原生Apple框架来读取条码,这是从iOS7起可用的。有关逐步教程,请参见


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.

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

Problem

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

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.

What did I found out

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

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

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

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.

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.

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

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.

So here I am, in StackOverflow.

One more point

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

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

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

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

解决方案

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 architecture settings across project. Give architecture and valid architecture as armv7 armv7s in your project settings, target settings, and ZXing project (which you added to your main project) and target settings.

  4. In main project -> Build Settings scroll and find out the options, C++ Language Dialect and 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

These fixed the issue for me..

Update

On December 2013, Google has retired ZXing iOS/Objective C port. So Zxing project for iOS is no longer maintained and updated for new iOS versions. Also Zxing doesn't have support for Arm64 architecture which is one of the standard architecture as per new XCode versions.

So developers are encouraged to move over to the native Apple framework to read barcode which is available from iOS7 onwards. See this for a step by step tutorial.

这篇关于在XCode 4.5中使用ZXing库时,架构armv7的未定义符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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