Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ linking problems, seems like I can't link against standard C++ stuff

Tags:

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)
like image 631
D.C. Avatar asked Oct 11 '12 22:10

D.C.


People also ask

How is standard library linked?

No, the standard libraries by default are dynamically linked at runtime. When running the dynamic loader will look in a couple of standard places for dynamic libraries if it finds it loads and runs otherwise the application quits. There are also a couple of Environment variables that can affect the search path.

Why is the linking step necessary in C?

The linking step is necessary to resolve all the references to external functions and to include the machine code for those functions in the final executable. Why is "linking" a "separate step"? You need at least two "separate steps" to get the assembler output, and two separate steps after that to get an executable.

What is meant by linking process in C?

Linking is the process of collecting and combining various pieces of code and data into a single file that can be loaded (copied) into memory and executed.


2 Answers

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!

like image 154
D.C. Avatar answered Oct 21 '22 23:10

D.C.


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

like image 36
TenaciousJay Avatar answered Oct 22 '22 01:10

TenaciousJay