13

As many of you noticed; zxing does not work in latest xcode (4.5/ios 6)

Here is use case:

  1. checkout latest version from trunk (as some fixes were already added)
  2. create single view application in xcode 4.5 with ios 6.0
  3. use README to add dependencies, paths etc (just follow step by step)
  4. add zxingcontroller call to class (renamed to mm)

Compilation fails both for simulator and device It shows 31 error like this one:

Undefined symbols for architecture i386:
  "std::string::c_str() const", referenced from

all 31 errors are similar, difference is in symbols name

May be somebody knows how to solve it with this use case?

p.s. if you have app from previous Xcode, it works. Problem is only if you create new app in Xcode 4.5

Till
  • 27,559
  • 13
  • 88
  • 122
Alan Harper
  • 793
  • 1
  • 10
  • 23
  • At this time, using the latest version of zxing, without changing compiler versions, architecture standards or other fixes such as detailed above, this is the way I managed to integrate zxing qr core reader into an ios6 project: > http://stackoverflow.com/a/14404363/1188082 – mircaea Jan 18 '13 at 17:38
  • This modifications work (tested): http://code.google.com/p/zxing/source/detail?r=2566# – Rok Jarc Mar 11 '13 at 17:02

3 Answers3

32

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

enter image description here


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.

enter image description here

Till
  • 27,559
  • 13
  • 88
  • 122
  • 4
    this is good for simulator; but still problem when building for a device: Undefined symbols for architecture armv7s: "_OBJC_CLASS_$_ZXingWidgetController", referenced from – Alan Harper Oct 01 '12 at 00:19
  • Till - thank you so much! this question is pretty common in zxing community now; your screenshots will save lot's of time; thanks again – Alan Harper Oct 01 '12 at 00:33
  • Go ahead, link this question and the answer within that community. Maybe some more upvotes for you will be generated :D – Till Oct 01 '12 at 00:34
  • totally awesome, been looking for a solution for hours. Fixed my problem – pnizzle Oct 10 '12 at 12:31
  • thank you man! you saved a lot of time for me! altho it had nothing in common with zxing – dreamzor Oct 13 '12 at 18:44
  • Thanks heaps !! I have spent almost whole day on solving this!! – nluo Nov 27 '12 at 06:57
  • But how come setting the "C++ Standard Library" to complier default will solve the issues? My project's original setting for "C++ Standard Library" is "LLVM C++ standard library with C++ 11 support", what is the difference between this one compared to the complier default? Thanks in advance! – nluo Nov 27 '12 at 07:02
  • 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, subprojects 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. – Till Nov 27 '12 at 11:29
  • Thanks man, that saved me a lot of time! Additionally, make sure you have all the libraries added to the "Link Binary with Libraries" under the Build Phases section. You can copy the list from the ScanTest project. Odds are a lot of these libs are not needed for simulator deployment, but the project will fail to build when you try to run it on an actual device. – Kevin R Feb 10 '13 at 20:48
  • You just made my day ! Having issues with libGlui and my project in XCode. libGlui was compiled with gcc, so I set the standard library accordingly. Thanks a lot !!! – dvkch Jun 26 '13 at 18:36
2

You might also want to switch the "Other Warning Flag" -Werror off. Seems to be necessary in Xcode versions > 4.5 (LLVM compiler > 4.1).

Gerd
  • 328
  • 1
  • 2
  • 9
0

It works for me, have you enabled -lstdc++ in your list of Other Linker Flags in the Build Settings tab of the project target? It sounds like it is not recognizing the c++ symbols needed for zXing to build. If this is the case, the above advice should help.

phoganuci
  • 4,984
  • 9
  • 39
  • 50
  • I've just added to my target (click on my xcode project, pick target and Build setting) - still the same; thank – Alan Harper Oct 01 '12 at 00:00
  • That should not be needed, the Standard C++ library is commonly linked by default once you are using ObjectiveC++ code (mm-files). – Till Oct 01 '12 at 00:39