简体   繁体   中英

zxing in xcode 4.5 and ios 6

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?

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

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

Actually, whenever you see linker failures in relationship with standard library objects (eg 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

在此输入图像描述


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 .

在此输入图像描述

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM