Reputation: 13956
I compiled Tesseract following the instructions here, which worked fine. But when I linked it with the sample c program from the docs, it gave me the following errors:
"std::__1::basic_streambuf<char, std::__1::char_traits<char> >::~basic_streambuf()", referenced from:
std::__1::basic_filebuf<char, std::__1::char_traits<char> >::~basic_filebuf() in libtesseract.a(libtesseract_api_la-baseapi.o)
std::__1::basic_filebuf<char, std::__1::char_traits<char> >::basic_filebuf() in libtesseract.a(libtesseract_api_la-baseapi.o)
"std::__1::cin", referenced from:
tesseract::TessBaseAPI::ProcessPagesInternal(char const*, char const*, int, tesseract::TessResultRenderer*) in libtesseract.a(libtesseract_api_la-baseapi.o)
Obviously it's trying to link the C++ standard library. Is it possible to compile as pure c, without the C++ standard lib? I want to eventually cross compile for arm-7 without standard lib support.
Here is my makefile (And no, the answer is not turn gcc to g++. I want to compile as c):
CFLAGS = -c -Wall -I../src/api/ -I../src/ccstruct -I../src/ccutil -I../leptonica/src/ -I../leptonica/build/src
default: main
main.o: main.c
gcc $(CFLAGS) -c main.c -o main.o
main: main.o
gcc main.o ../leptonica/lib/nodebug/liblept.a ../src/api/.libs/libtesseract.a -o main
clean:
-rm -f *.o
-rm -f main
Upvotes: 1
Views: 1462
Reputation: 26066
In general, C++ applications require/depend on the C++ standard library in several ways. Therefore, you should either provide the dependency or, if you really want to avoid it, statically link it. In addition, avoid statically linking several times the standard library (if several of your dependencies based on C++ require it).
Having said that, your next goal of avoiding entirely the C++ standard library is way harder. Not only you will have to provide alternative implementations of the C++ standard types & functions that Tesseract seems to use (or modify the library to avoid their use); but you will have to deal with several other issues: exceptions, RTTI, startup code & constructors, calls to special functions generated by the compiler like memcpy
, linking to libgcc
...
Upvotes: 1