Zxing in Xcode 4.5 and iOS 6

zxing in xcode 4.5 and ios 6

The issue you have encountered seems to be C++ standard library related.

Actually, whenever you see linker failures in relationship with standard library objects (e.g. std::string), you should check the project settings on all linked libraries and the app-project itself. They usually need to match!

The original ScanTest (which builds ZXingWidget as a subproject) uses the following settings and those need to match your App build-settings if you use the library as is.

For making sure, I created a brand-new project using Xcode 4.5. That project uses ZXingWidget as a prebuilt library but not as a subproject - I dont like subprojects for stuff that is not my own - though this specialty wont influence the results.

The important setting is C++ Standard Library - make sure that is set towards Compiler Default

Sample Image


Little clarification

Actually, you do not need to use C++ Standard Library, you may as well use LLVM C++ standard library with C++11 support. But you will have to use that exact same library in all projects, sub-projects and libraries that link with your project. So if you insist on using the more recent version of that library (C++11 support), then you will have to build the ZXing library with those settings as well.


Last but not least, make sure your Architectures and Valid Architecture settings are matching over all projects and sub projects (fixing the common armv7s linker issue).

First, make sure your Architectures setting is set towards armv7 armv7s within all projects. Then also edit the project settings of all projects towards Valid Architecture armv7s armv7.

Sample Image

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

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.

Add zebra crossing to a project Xcode 4.5

Take a look at CocoaPods website cocoapods.org.

I was trying to add ZXing to my project for ages. In the end I used cocoapods and it worked with no problems.

Editing answer as per request...

The answer is just add the armv7s to the ZXingWidget project under Architectures and in the ZXingWidget library in Architectures.

Everyone should get CocoaPods though. it really is an amazing tool. All the frameworks I use go through it.

ZXing in XCode 4.6.2 Linking Errors

I was able to fix my build. The ZXingWidget project refers to files in the cpp folder which resides in a folder at the same level as my main project. This is how the ZXing documentation says to do it (and it was working before I upgraded XCode) even though it doesn't make total sense to me. So the folders look like this:

  • Base folder
    • cpp
    • My project
      • ZXingWidget

The instructions for including ZXingWidget in your project tell you to add ../../cpp/core/src to your searched headers. The files the linker was complaining about are all in there, so I manually added each one the linker complained about to the Compile Sources in the ZXingWidget project's target.

After that I only had one linker error, which I fixed by changing the Deployment Target on my main project and it's target from 3.0 to 5.1.1 (I would have set it to 4.3, but it said the armv64 architecture had a minimum of 5.1.1 - don't know if I need that architecture, but whatever).

zxing reader in landscape mode

Zxing library uses AVFoundation framework to show live camera layer. This layer(prevLayer) is added on the ZXingWidgetController's view layer in initCapture method. So whenever you rotate your camera this layer also rotate. To keep this layer in fixed position you will need to rotate it again by 0, M_PI, -M_PI/2, M_PI/2 in portrait, upsideDown, landscapeRight, landscapeLeft using following rotation transform

CATransform3D transform =  CATransform3DMakeRotation(angle, 0, 0, 1.0);
self.prevLayer.transform =transform;
self.prevLayer.frame = frame; // you may need to set it also if needed.



Related Topics



Leave a reply



Submit