20

I am trying to use a library I've compiled myself in an iOS app. The library is the Tesseract OCR lib. It seems like compiling that (and its dependencies) have gone ok.

However, when I try to link against this lib in my app project, the app fails to link. The link errors surprise me; it seems like there are problems with the Tesseract stuff finding pretty standard C++ stuff.

Any suggestions about what I might be doing wrong would be most helpful.

Here is a snippet of the kind of link errors I'm seeing.

Undefined symbols for architecture armv7:
"std::string::find_last_of(char const*, unsigned long) const", referenced from:
  tesseract::WordSizeModel::Init(std::string const&, std::string const&) in    libtesseract.a(word_size_model.o)
"std::string::find_first_of(std::string const&, unsigned long) const", referenced from:
  tesseract::CubeUtils::SplitStringUsing(std::string const&, std::string const&, std::vector<std::string, std::allocator<std::string> >*) in libtesseract.a(cube_utils.o)
"std::string::find_first_not_of(std::string const&, unsigned long) const", referenced from:
  tesseract::CubeUtils::SplitStringUsing(std::string const&, std::string const&, std::vector<std::string, std::allocator<std::string> >*) in libtesseract.a(cube_utils.o)
"std::string::data() const", referenced from:
  tesseract::CubeUtils::SplitStringUsing(std::string const&, std::string const&, std::vector<std::string, std::allocator<std::string> >*) in libtesseract.a(cube_utils.o)
"std::string::find(char, unsigned long) const", referenced from:
  tesseract::TessLangModel::IsLeadingPunc(int) in libtesseract.a(tess_lang_model.o)
Cœur
  • 37,241
  • 25
  • 195
  • 267
D.C.
  • 15,340
  • 19
  • 71
  • 102
  • 1
    Maybe it's looking in the wrong location for `libstdc++`. You might want to check the output of `ldd` against `libtesseract.a`. http://unixhelp.ed.ac.uk/CGI/man-cgi?ldd+1 – Geoff Montee Oct 11 '12 at 22:28
  • looks like your source file name is wrong. The source file name should by *.cpp for C++ (or *.M (capitol M) for obj-C++). Basically you are using the C compiler for linking when you should be using the C++ compiler. – Martin York Oct 11 '12 at 22:47
  • Not sure where you are looking. I don't even see any references to a source code file. Just object files. – Geoff Montee Oct 11 '12 at 23:04
  • 2
    Loki thanks. yeah I thought this might be the problem, but I verified that the files do end in .mm which is correct. Geoff. Interesting, I will look into this suggestion. So does this error suggest to you that the .a library is build wrong. In other words, this can't be fixed in the app, it is a problem with the library itself? – D.C. Oct 12 '12 at 01:27
  • 2
    I resolved problem by renaming one of view controller from `ViewController.m` (single **m**) to `ViewController.mm` (double **m**). To be honest, I'm not sure why it worked out. I guess it somehow involves C++ compiler on compilation process and force it to use all correct paths regarding it. – iutinvg Mar 22 '13 at 03:35
  • http://stackoverflow.com/questions/18959691/ios7-only-stdlibc-linking-issue/19250215#19250215 worked for me – user678724 Jun 24 '14 at 05:33

5 Answers5

28

Thank you everyone for your answers. I found out what my particular problem was, so will share it here in case anybody else hits it.

My problem was a project build setting. Under "Apple LLVM Compiler 5.0 - Language - C++" there is a setting for "C++ standard library". Its value needed to be changed to "Compiler Default".

Several hours wasted, but problem solved!

Liz
  • 8,780
  • 2
  • 36
  • 40
D.C.
  • 15,340
  • 19
  • 71
  • 102
8

I am using a newer version of the iOS SDK and set "Build Settings > Apple LLVM 5.0 - Language - C++ > C++ standard library" to "Compiler Default" but got 46 compile errors.

I got rid of the errors by setting it to "libstdc++ (GNU C++ standard library)".

Hopefully this helps anyone who got stuck when using "Compiler Default".

TenaciousJay
  • 6,750
  • 3
  • 45
  • 48
1

Not sure if this will help anyone, but I had the same problem when I had a project linked with other projects when one had Base SDK as 5.1 and the other had Base SDK of 7.0.

raeldor
  • 503
  • 3
  • 11
0

Maybe you do not have SDK for armv7 architecture, so you can compile your code but standard C++ stuff that installed on your computer is for another architecture (for example x86) and your linker can't find libraries that required for this architecture

BigBoss
  • 6,904
  • 2
  • 23
  • 38
-1

The link error suggests that the c++ library cannot be found in the path. Without further information, I would suggest checking the path to the c++ library is correct.

bobestm
  • 1,334
  • 1
  • 9
  • 8
  • No, the link error suggests symbols were not found. There was no error to indicate that a linked library was not found in any search path. – Kaa Aug 19 '17 at 21:00