I'm currently attempting to make an existing project to link statically to its main dependency in order to reduce size of the resulting output library. The project I'm trying to change is Tesseract OCR that depends on Leptonica image processing library.
At the time being, Leptonica counts 2481 functions but Tesseract uses only 163 of them. In other words, only 6,6% of Leptonica functionality is used in Tesseract but the whole bunch of code (3,5 MB + additional libraries) will be loaded and kept in memory. It's probably not an issue at all for desktop systems. But on mobile devices with limited memory, it's too costly to have several MBs occupied by unused code.
I hope to reduce the overall size of this Tesseract+Leptonica couple using static linking. Both projects utilize autoconfig/automake/libtool build system.
Leptonica's build produces both static and dynamic libraries. Tesseract uses the following line in its configure.ac in order to declare Leptonica dependency:
AC_CHECK_LIB(lept,pixCreate,[],AC_MSG_ERROR([Leptonica library missing]))
Because the above mentioned line does add Leptonica automatically to $LIBS, I've changed this as follows:
AC_CHECK_LIB(lept,pixCreate,[LIBS="-Bstatic -llept -Bdynamic $LIBS"],AC_MSG_ERROR([Leptonica library missing])))
When I run ./configure and make, everything goes right but Tesseract will still be dynamically linked to Leptonica.
While examining the corresponding make log, I noticed that the g++ linking invocation simply ignores my "-Bstatic" attribute and links to the shared library (liblept.so) instead:
libtool: link: g++ -m32 -fPIC -DPIC -shared -nostdlib /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crti.o /usr/lib/gcc/i686-linux-gnu/4.8/crtbeginS.o -Wl,--whole-archive ./.libs/libtesseract_api.a ../ccmain/.libs/libtesseract_main.a ../cube/.libs/libtesseract_cube.a ../neural_networks/runtime/.libs/libtesseract_neural.a ../textord/.libs/libtesseract_textord.a ../wordrec/.libs/libtesseract_wordrec.a ../classify/.libs/libtesseract_classify.a ../dict/.libs/libtesseract_dict.a ../ccstruct/.libs/libtesseract_ccstruct.a ../cutil/.libs/libtesseract_cutil.a ../viewer/.libs/libtesseract_viewer.a ../ccutil/.libs/libtesseract_ccutil.a ../opencl/.libs/libtesseract_opencl.a -Wl,--no-whole-archive -Wl,-rpath -Wl,/home/maxpol/Dokumente/javacpp-presets-myfork/tesseract/cppbuild/linux-x86/lib -Wl,-rpath -Wl,/home/maxpol/Dokumente/javacpp-presets-myfork/tesseract/cppbuild/linux-x86/lib -L/home/maxpol/Dokumente/javacpp-presets-myfork/tesseract/cppbuild/linux-x86/lib/ -lz /home/maxpol/Dokumente/javacpp-presets-myfork/tesseract/cppbuild/linux-x86/lib/liblept.so -lpthread -L/usr/lib/gcc/i686-linux-gnu/4.8 -L/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu -L/usr/lib/gcc/i686-linux-gnu/4.8/../../../../lib -L/lib/i386-linux-gnu -L/lib/../lib -L/usr/lib/i386-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/i686-linux-gnu/4.8/../../.. -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/i686-linux-gnu/4.8/crtendS.o /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crtn.o -m32 -pthread -Wl,-soname -Wl,libtesseract.so.3 -o .libs/libtesseract.so.3.0.4
I've already consulted the autotools docs and several other projects but couldn't find anything helpful. Therefore I decided myself to ask this question here.
Am I missing something important?
Thank you very much in advance for your help! Best regards Max