How to install ZXing in Xcode 4

After an upgrading to Xcode 4, I have been having trouble compiling my own ZXing iOS project. That’s why I decided to explain you how to install easily ZXing with Xcode 4.

First of all (for those who don’t know), ZXing is an open-source library to read the 1D/2D barcodes. This library is available on many platforms such as the iOS, Android, Blackberry, ect. You can find it here: http://code.google.com/p/zxing/.

Before to start, be sure that you have the latest version of ZXing on your computer. If you don’t, you must download it via a SVN client here: http://zxing.googlecode.com/svn/trunk/.

To use ZXing into your project in Xcode 4 follow these steps:

  1. Firstly go to the “zxing/iphone/ZXingWidget/” and drag and drop the ZXingWidget.xcodeproj file onto your Xcode “Project navigator” sidebar. If a dialog appears uncheck the “Copy items” and verify that the “Reference Type” is “Relative to Project” before clicking “Add”.

  2. Now we are going to add ZXingWidget as a dependency of your project to allow Xcode to compile it whenever you compile the main project:
    1. First select your project file in the “Project navigator”.
    2. Then select the corresponding target.
    3. After choose the “Build Phases” tab and expand the “Target Dependencies” section.
    4. Click the “+” (add) button to display a dialog.
    5. To finish add the “ZXingWidget” target as shown above.

  3. Now we are going to link the ZXingWidget static library (libZXingWidget.a) to the project:
    1. Firstly choose the “Build Phases” tab and expand the “Link Binary With Libraries” section.
    2. Then click the “+” (add) button to display a dialog.
    3. To finish add the “libZXingWidget.a” which is located in the “Workspace” category as shown above.
    4. By the way add the following iOS frameworks too:
      • AddressBook
      • AddressBookUI
      • AudioToolbox
      • AVFoundation
      • CoreMedia
      • CoreVideo
      • libiconv.dylib

  4. Then you must configure the header search path of your project to allow Xcode to find the ZXingWidget headers. To do that:
    1. In the “Project navigator” select the main project (not the target).
    2. Go to the “Build Settings” tab and search the “Header Search Paths“.
    3. Double-click on it and add:
      • The full path of the “zxing/iphone/ZXingWidget/Classes” directory. Check the “recursive path“.
      • The full path of the “zxing/cpp/core/src/” directory. Uncheck the “recursive path“.

Now you just have to import the “ZXingWidgetController.h” and the “QRCodeReader.h” to your project and use them.
Attention: Make sure that the files in which you are using the ZXing headers have the .mm extension because they use c++ library files.

Voilà! Now all should be ok. I hope it’ll help you!

1 Star2 Stars3 Stars4 Stars5 Stars (37 votes, average: 4.57 out of 5)
Loading...

87 comments

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  1. Liliana Sousa · April 17, 2011

    Hi.

    I was having same problem as many: No such file or directory for the headers ZXingWidgetController.h and QRCodeReader.h.
    I solved the problem by adding the directories not only to “Header Search Paths” but also to “User Header Search Paths”!

    Cheers
    Liliana

  2. anusha · April 17, 2011

    hi
    i included zxing into my native application m getting the error like “Universalresult parser.h” file not found….how can i remove these error

    pls help me

  3. rock · April 17, 2011

    謝謝。
    你的網頁,對我來說是很有幫助的。

    Thank you.
    Your pages is helpful for me.

  4. neil · April 17, 2011

    Well done. Nice tutorial. Works!
    Step 1 didn’t show the mentioned dialog.

  5. Pingback: Building an iPhone app – Drupal, jQuery Mobile and PhoneGap : Knownzeros
  6. Damien · April 17, 2011

    It took me a while to follow your instructions *correctly* 🙂

    When I did, it was a massive help. For my PhoneGap app, I also had to disable Automatic Reference Counting, remove the AudioUnit lib and add the AssetsLibrary lib to resolve compilation issues.

    I would not have figured this out without your excellent article, many thanks!

  7. dgeneva · April 17, 2011

    Worked like a charm for me. Thanks a lot for your post.

  8. Quentin · April 17, 2011

    Hi, after all those steps, I have a iostream file missing 😡
    Do you have any ideas why this error occurs now ?

  9. Pingback: ZXingをXcodeプロジェクトに組み込む - @blog.justoneplanet.info
  10. Sacha · April 17, 2011

    Thanks for the tutorial!
    But on this line: #import “ZXingWidgetController.h” I get the error file not found…
    Do you know why there’s this error?

    Cheers.

  11. jose · April 17, 2011

    Please help me:
    I one error compilation

    libZXingWidget.a is red and I not found in the directory.

    ld: library not found for -lZXingWidget
    Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 1

    Tnank you

  12. Razor · April 17, 2011

    @All thos who get #import “ZXingWidgetController.h” error file not found,
    Try to do the following:-

    1) Download the SVN version of the code, not the zipped code.
    2) Check if you have set an absolute path to your ZXingWidget project.
    3) Make sure it is recursive (Append **, at the end)

    I got it working after doing these. Thanks for the tutorial. keep up the good work.

    Note: ZXing doesn’t support Barcode scan yet. SO use it only for QRCodes.

  13. Kin · April 17, 2011

    Hi, Thanks for your great tutorial. By playing with the example file in ZXing i found that they are all using the AVfoundation the capture method. I would like to ask how can I use the old way which sending a UIImage to the decoder and decode. I would like to pick Image from Imagepicker.

  14. James · April 17, 2011

    Hi,

    I installed ZXing in my project, but can not find examples to activate the camera and read a QR code.
    You know a URL?

    thanks

  15. smotion · April 17, 2011

    I have the same problem with James . I can not active the camera and read a QR code

    Could you help me ?

  16. CrizZ · April 17, 2011

    Thanks for your describtion! It helped me a lot!

  17. Sudhanshu · April 17, 2011

    I tried it several times but still same issue “ZXingWidgetController.h” file not found. I don’t know what I am missing but I have followed each and every step. Tired…… Please help me

    • Sudhanshu · April 17, 2011

      aaahh! it was my mistake. there was an empty line automatically generated between Debug and Release in Header Search Path. I deleted that and it is working fine.. Thanks for the great tutorial.

      • Himanshu · April 17, 2011

        Hey can u help me! I am stragling with issue #import “ZXingWidgetController.h” file not found in my My App. How to over come with this?

  18. Himanshu · April 17, 2011

    #import “ZXingWidgetController.h” I get the error file not found…
    i have tried every thing on Header search Path. But i am not getting correct way
    to fix this issue

  19. Pingback: How to install ZXing in Xcode 4 « Yannick Loriot | BRAE
  20. Himanshu · April 17, 2011

    #import “ZXingWidgetController.h” I get the error file not found…
    i have tried every thing on Header search Path. But i am not getting correct way
    to fix this issue plz help

  21. Pingback: Problen in to import #import ZXingWidgetController.h un iphone app?
  22. Francisco Gutiérrez · April 17, 2011

    Hi, here’s the solution behind #import “ZXingWidgetController.h”
    You need to verify the path of your files here’s my example:

    My current project path:
    ~/Dropbox/Tesis Project/Celedex
    My current library ZXing:
    ~/Dropbox/Tesis Project/ZXingWidget

    So the header search paths look like this:
    ../ZXingWidget/Classes (recursive)
    ../../cpp/core/src (non-recursive)

    Good luck, and best wishes.

  23. Francisco Gutiérrez · April 17, 2011

    Guess what?, I’m using now ZBar it solved a lot of problems to me, if you want your app running with custom low-level features, and also a simple install process, go here: http://zbar.sourceforge.net/iphone/sdkdoc/install.html works fine for me, it’s up to you.

    Btw, congrats on this post, it’s awesome.

    Cheers.

  24. Kristine · April 17, 2011

    What tutorial? People don’t you read “READ ME” files included in the Zxing???? This is just a copy paste >:(

  25. Pingback: Xcode4.6 中整合 zxing 库
  26. Pingback: Yannick Loriot | How To Move From ZXing to ZBar
  27. sourabh · April 17, 2011

    I want to copy ZxingWidget Static library in my project so that when i run on other system then i dont need any dependency to download and give path,
    Please tell me what steps i should follow

  28. johny · April 17, 2011

    I am getting below error

    clang: error: no such file or directory: ‘/Users/alfa-1/Documents/Zxings/1/ZXingWidget/../../cpp/core/src/zxing/common/BitSource.cpp’
    clang: error: no input files
    Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 1

  29. Lalit · April 17, 2011

    Thanks for the great explanation.
    I added header search path to the project not to the targets. I downloaded the zxing on the Desktop and used the following path :
    /Users/xyz/Desktop/zxing-master/iphone/ZXingWidget/Classes (Recursive)
    /Users/afsarkhan/Desktop/zxing-master/cpp/core/src (non-recursive)

    and follow other instructions correctly. But while going for the build for profiling option, getting the following error

    #import “zxing/common/Counted.h” // not found

    I am using Xcode version 4.3.1 and deployment target is set to 5.1. Is ZXing integration not allowed with this version?
    Could you please help me out in resolving this?