I'm currently trying to create an existing project to link statically with its main dependency in order to reduce the size of the resulting output library. The project I'm trying to change is Tesseract OCR, which depends on the Leptonica image processing library.
Currently, Leptonic has 2481 functions, but Tesseract uses only 163 of them. In other words, only 6.6% of Leptonica functionality is used in Tesseract, but the entire code package (3.5 MB + additional libraries) will be downloaded and stored in memory. This is probably not a problem for desktop systems. But on mobile devices with limited memory, it is too expensive to have several MB occupied by unused code.
I hope to reduce the overall size of this Tesseract + Leptonica pair using static snapping. Both projects use the autoconfig / automake / libtool system.
Leptonica build creates both static and dynamic libraries. Tesseract uses the following line in its configure.ac to declare a dependency on Leptonica:
AC_CHECK_LIB(lept,pixCreate,[],AC_MSG_ERROR([Leptonica library missing]))
Since the above line automatically adds Leptonica to $ LIBS, I modified it 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.
When looking at the corresponding logbook, I noticed that calling the g ++ link simply ignores my "-Bstatic" attribute and links to the shared library (liblept.so):
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 already consulted with autotools docs and several other projects, but could not find anything useful. So I decided to ask this question here.
Did I miss something important?
Thank you for your help! Best regards max