Undefined Symbols for Architecture Armv7 When Using Zxing Library in Xcode 4.5

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.

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? What does this error mean?

It means that some code you are compiling is referencing the constants "kCFStreamNetworkServiceTypeVoIP", "kCFStreamNetworkServiceType", and "kCFStreamPropertySSLSettings", but that those constants weren't found when it tried to link your code with the libraries it uses.

Unfortunately there's a bunch of reasons this could be:

  • You could have misspelled them
  • They could be #ifdef'd out for that architecture
  • You might not be linking the correct librar(y, ies)
  • They could be marked as having 'hidden' visibility so that they can only be used in the declaring library
  • Probably other reasons

You can use 'nm' to poke at the exported symbols from the binary of a library, and 'otool -L' to check which libraries your binary is linking.

Undefined symbols for architecture armv7: _SCNetworkReachabilityCreateWithAddress

Normally, extra slashes won't muck up a UNIX-like build process.

But, you do need to make sure the armv7 architecture is inside the framework file that your build is trying to use. To do this, use the lipo -info command at the command line:

lipo -info /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer‌​/SDKs/iPhoneOS5.1.sdk/System/Library/Frameworks//SystemConfiguration.framework/Sy‌​stemConfiguration

You should see output like this:

Architectures in the fat file: SystemConfiguration are: armv6 armv7

If you don't, your project is probably set up to link to the wrong version of the SystemConfiguration.framework. There's multiple versions of that framework on your machine. So, I would verify the path of the framework (i.e. SystemConfiguration) that you have in your project.

Normally, I would expect that file to be something like this (adjusted for the OS version you're using):

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/System/Lib‌​rary/Frameworks/SystemConfiguration.framework

Undefined symbols for architecture armv7, ld: symbol(s) not found for architecture armv7 - what to do?

make sure you add ArtworkScrollerViewController.m to the target that you are building

Undefined symbols for architecture armv7 when adding CocoaAsyncSocket

You just need to add SecurityFramework in the Frameworks. I also met this same problem.



Related Topics



Leave a reply



Submit