Bug 708849 - ghostscript 10.06.0 ocr/tesseract fails to build with system libraries (tesseract/leptonica)
Summary: ghostscript 10.06.0 ocr/tesseract fails to build with system libraries (tesse...
Status: UNCONFIRMED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Build Process (show other bugs)
Version: 10.06.0
Hardware: PC Linux
: P2 normal
Assignee: Default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-09-19 07:46 UTC by Timo Gurr
Modified: 2025-09-25 14:00 UTC (History)
2 users (show)

See Also:
Customer:
Word Size: ---


Attachments
ghostscript-10.06.0_build.log (968.93 KB, text/x-log)
2025-09-19 07:47 UTC, Timo Gurr
Details
ghostscript-10.06.0-build-log-of-working-with-patch.log (1.83 MB, text/x-log)
2025-09-22 17:16 UTC, Timo Gurr
Details
ghostscript-gpl-10.06.0-tesseract-fPIC.patch (1.83 KB, patch)
2025-09-25 14:00 UTC, Timo Gurr
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Timo Gurr 2025-09-19 07:46:44 UTC
Additional note: Version 10.06.0 is not available for selection in Bugzilla

ghostscript 10.06.0 fails with:

[...]
./soobj/aux/echogs -a ./soobj/ldt.tr -n -s ./soobj/gsromfs0.o  -s
cat ./soobj/gsld.tr >> ./soobj/ldt.tr
./soobj/aux/echogs -a ./soobj/ldt.tr -s -  -lm -ldl  -lidn -lpaper -ltiff -rdynamic -lfontconfig -lfreetype -lopenjp2  -lpthread -lm -ltesseract -larchive -lcurl -lleptonica -lstdc++
if [ x != x ]; then LD_RUN_PATH=; export LD_RUN_PATH; fi; \
XCFLAGS= XINCLUDE= XLDFLAGS= XLIBDIRS= XLIBS= \
PSI_FEATURE_DEVS= FEATURE_DEVS= DEVICE_DEVS= DEVICE_DEVS1= DEVICE_DEVS2= DEVICE_DEVS3= \
DEVICE_DEVS4= DEVICE_DEVS5= DEVICE_DEVS6= DEVICE_DEVS7= DEVICE_DEVS8= \
DEVICE_DEVS9= DEVICE_DEVS10= DEVICE_DEVS11= DEVICE_DEVS12= \
DEVICE_DEVS13= DEVICE_DEVS14= DEVICE_DEVS15= DEVICE_DEVS16= \
DEVICE_DEVS17= DEVICE_DEVS18= DEVICE_DEVS19= DEVICE_DEVS20= \
DEVICE_DEVS_EXTRA= \
/bin/sh <./soobj/ldt.tr

Error:
  * In program cave perform install --hooks --managed-output --output-exclusivity with-others =app-text/ghostscript-10.06.0:0::arbor --destination installed --replacing =app-text/ghostscript-10.05.1:0::installed --x-of-y 1 of 1:
  * When installing 'app-text/ghostscript-10.06.0:0::arbor' replacing { 'app-text/ghostscript-10.05.1:0::installed' }:
  * When running an ebuild command on 'app-text/ghostscript-10.06.0:0::arbor':
  * Install failed for 'app-text/ghostscript-10.06.0:0::arbor' (paludis::ActionFailedError)

make[2]: Leaving directory '/var/tmp/paludis/build/app-text-ghostscript-10.06.0/work/ghostscript-10.06.0'
make[1]: Leaving directory '/var/tmp/paludis/build/app-text-ghostscript-10.06.0/work/ghostscript-10.06.0'
/usr/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-ld: ./soobj/tessocr.o: warning: relocation against `_ZN9tesseract14ResultIteratorD0Ev' in read-only section `.text'
/usr/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-ld: ./soobj/tessocr.o: relocation R_X86_64_PC32 against symbol `leptonica_free' can not be used when making a shared object; recompile with -fPIC
/usr/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [base/unixlink.mak:172: sobin/libgs.so.10.06] Error 1
make[1]: *** [base/unix-dll.mak:321: so-only-subtarget] Error 2
make: *** [base/unix-dll.mak:281: so] Error 2

While the previous ghostscript version 10.05.1 still buildt and builds fine:

app-text/ghostscript-10.05.1:0::installed
    64-bit:
        Dependencies (declared, enabled):
            app-text/tesseract-5.5.1:0::installed
                /usr/x86_64-pc-linux-gnu/lib/libtesseract.so.5.0.5
            dev-libs/libpaper-2.1.2:0::installed
                /usr/x86_64-pc-linux-gnu/lib/libpaper.so.2.1.2
            media-libs/OpenJPEG-2.5.3:2::installed
                /usr/x86_64-pc-linux-gnu/lib/libopenjp2.so.2.5.3
            media-libs/fontconfig-2.16.2:0::installed
                /usr/x86_64-pc-linux-gnu/lib/libfontconfig.so.1.15.0
            media-libs/freetype-2.14.0:2::installed
                /usr/x86_64-pc-linux-gnu/lib/libfreetype.so.6.20.3
            media-libs/jbig2dec-0.20:0::installed
                /usr/x86_64-pc-linux-gnu/lib/libjbig2dec.so.0.0.0
            media-libs/lcms2-2.17:0::installed
                /usr/x86_64-pc-linux-gnu/lib/liblcms2.so.2.0.17
            media-libs/leptonica-1.85.0:0::installed
                /usr/x86_64-pc-linux-gnu/lib/libleptonica.so.6.0.0
            media-libs/libjpeg-turbo-3.1.2:0::installed
                /usr/x86_64-pc-linux-gnu/lib/libjpeg.so.8.3.2
            media-libs/libpng-1.6.50:1.6::installed
                /usr/x86_64-pc-linux-gnu/lib/libpng16.so.16.50.0
            media-libs/tiff-4.7.0:6::installed
                /usr/x86_64-pc-linux-gnu/lib/libtiff.so.6.1.0
            net-dns/libidn-1.43:0::installed
                /usr/x86_64-pc-linux-gnu/lib/libidn.so.12.6.6
            net-print/cups-2.4.14:0::installed
                /usr/x86_64-pc-linux-gnu/lib/libcups.so.2
            sys-libs/zlib-1.3.1:0::installed
                /usr/x86_64-pc-linux-gnu/lib/libz.so.1.3.1
            x11-libs/libX11-1.8.12:0::installed
                /usr/x86_64-pc-linux-gnu/lib/libX11.so.6.4.0
            x11-libs/libXt-1.3.1:0::installed
                /usr/x86_64-pc-linux-gnu/lib/libXt.so.6.0.0

        Dependencies (undeclared):
            sys-libs/glibc-2.42-r1::installed
                /usr/x86_64-pc-linux-gnu/lib/libc.so.6
                /usr/x86_64-pc-linux-gnu/lib/libm.so.6
            sys-libs/libgcc-15.2.0::installed
                /usr/x86_64-pc-linux-gnu/lib/gcc/x86_64-pc-linux-gnu/15/libgcc_s.so.1
            sys-libs/libstdc++-15.2.0::installed
                /usr/x86_64-pc-linux-gnu/lib/libstdc++-15.so.6.0.34

Systen installed versions are:

leptonica: 1.85.0 (but also with the just released 1.86.0)
tesseract: 5.5.1

The complete build log is attached.
Comment 1 Timo Gurr 2025-09-19 07:47:05 UTC
Created attachment 27244 [details]
ghostscript-10.06.0_build.log
Comment 2 Chris Liddell (chrisl) 2025-09-22 14:25:00 UTC
On Ubuntu 24.04.3 LTS the build runs to completion with all the same shared libraries you would be relying on (given the "rm -r ./cups/libs ./brotli ./freetype ./jbig2dec ./jpeg ./lcms2mt ./leptonica ./libpng ./openjpeg ./tesseract ./tiff ./zlib" line from your build log).

I can't see anything that's changed with the tesseract integration since 10.05.0 was released.

I'm not sure how to proceed.
Comment 3 Timo Gurr 2025-09-22 15:53:11 UTC
(In reply to Chris Liddell (chrisl) from comment #2)
> On Ubuntu 24.04.3 LTS the build runs to completion with all the same shared
> libraries you would be relying on (given the "rm -r ./cups/libs ./brotli
> ./freetype ./jbig2dec ./jpeg ./lcms2mt ./leptonica ./libpng ./openjpeg
> ./tesseract ./tiff ./zlib" line from your build log).
> 
> I can't see anything that's changed with the tesseract integration since
> 10.05.0 was released.
> 
> I'm not sure how to proceed.

Thanks for looking into it, after your message I also had a deeper look and found 

https://github.com/ArtifexSoftware/ghostpdl/commit/ad18a3036bda27fcd74e08050834d7db4aafe7e2

as the offending commit. And reverting the line in ocr.mak

diff -Naur ghostpdl-ghostpdl-10.06.0/base/ocr.mak ghostpdl-ghostpdl-10.06.0.new/base/ocr.mak
--- ghostpdl-ghostpdl-10.06.0/base/ocr.mak	2025-09-09 11:34:47.000000000 +0200
+++ ghostpdl-ghostpdl-10.06.0.new/base/ocr.mak	2025-09-22 16:33:56.222499979 +0200
@@ -20,7 +20,7 @@
 
 # Define the name of this makefile.
 LIBOCR_MAK=$(GLSRC)ocr.mak $(TOP_MAKEFILES)
-OCRCXX = $(CXX) $(TESSINCLUDES) $(TESSCXXFLAGS) $(CCXXFLAGS) -DTESSERACT_IMAGEDATA_AS_PIX -DTESSERACT_DISABLE_DEBUG_FONTS -DGRAPHICS_DISABLED -UCLUSTER
+OCRCXX = $(CXX) $(TESSINCLUDES) $(TESSCXXFLAGS) $(CCFLAGS) -DTESSERACT_IMAGEDATA_AS_PIX -DTESSERACT_DISABLE_DEBUG_FONTS -DGRAPHICS_DISABLED -UCLUSTER
 
 # Tesseract veneer.
 $(GLGEN)tessocr.$(OBJ) : $(GLSRC)tessocr.cpp $(GLSRC)tessocr.h $(LIBOCR_MAK) \

allows my build to succeed.

Though I'm not sure how to fix this properly, for other flags we use the *AUX option to specify/pass our own like CPPFLAGSAUX for example but there doesn't seem to be a similiar one for CCXXFLAGSAUX. We set those for cross-compiliation https://gitlab.exherbo.org/exherbo/arbor/-/blob/master/packages/app-text/ghostscript/ghostscript-10.05.1.exheres-0?ref_type=heads#L115-L118 the relevant bug back then was https://bugs.ghostscript.com/show_bug.cgi?id=701689.
Comment 4 Chris Liddell (chrisl) 2025-09-22 16:17:07 UTC
Unfortunately, that's just left me even more confused.

That commit replaces the variable CCFLAGS with the variable CCXXFLAGS, which should contain all the same options as CCFLAGS _except_ "-Wstrict-prototypes" and "-Wmissing-prototypes" neither of which are relevant for C++.

So any options that were being pass through the configure script and included in CCFLAGS should also end up in CCXXFLAGS.


The comment about the *AUX options confuses me even further, since those are used when building the interim tools (genconf, genarch, and mkromfs) which are called during the build, in the build environment (not the host), and none of them use C++ nor should they be linking to tesseract.
Comment 5 Chris Liddell (chrisl) 2025-09-22 17:12:03 UTC
(Note that I'm not discounting that I may have messed something up, just trying to get my head around what's happening)
Comment 6 Timo Gurr 2025-09-22 17:15:50 UTC
(In reply to Chris Liddell (chrisl) from comment #4)
> Unfortunately, that's just left me even more confused.
> 
> That commit replaces the variable CCFLAGS with the variable CCXXFLAGS, which
> should contain all the same options as CCFLAGS _except_
> "-Wstrict-prototypes" and "-Wmissing-prototypes" neither of which are
> relevant for C++.
> 
> So any options that were being pass through the configure script and
> included in CCFLAGS should also end up in CCXXFLAGS.
> 
> 
> The comment about the *AUX options confuses me even further, since those are
> used when building the interim tools (genconf, genarch, and mkromfs) which
> are called during the build, in the build environment (not the host), and
> none of them use C++ nor should they be linking to tesseract.

That was my mistake then of course, I thought things could be related due to the fact that I have no real clue where to look for. All I have for now is that the "patch" altering that line to what is was before allows gs to build. I tried to see if I can find something diffing a failed and a working build log but couldn't spot anything obvious apart from having the addition three warning lines on a working build

cc1plus: warning: command-line option '-Wstrict-prototypes' is valid for C/ObjC but not for C++
cc1plus: warning: command-line option '-Wmissing-prototypes' is valid for C/ObjC but not for C++
cc1plus: warning: '-Werror=' argument '-Werror=declaration-after-statement' is not valid for C++

which is what you mentioned before. I'll try to revert the whole commit tomorrow and see if it fails then as well or if there's something else I can find out, as you already saw I'm kinda lost here as I'm not that deep into build stuff sorry for that and any false conclusions I might do. For now I'm attaching a build log from a working build.
Comment 7 Timo Gurr 2025-09-22 17:16:19 UTC
Created attachment 27251 [details]
ghostscript-10.06.0-build-log-of-working-with-patch.log
Comment 8 Michael Osipov 2025-09-25 06:53:12 UTC
Port maintainer on FreeBSD here: Committed 10.06.0 yesterday and received the very same issue from a fellow committer. I will try the one-off patch in the Makefile.
Comment 9 Michael Osipov 2025-09-25 09:49:14 UTC
The reverse patch works for me: https://reviews.freebsd.org/D52722
Comment 10 Timo Gurr 2025-09-25 14:00:41 UTC
Created attachment 27264 [details]
ghostscript-gpl-10.06.0-tesseract-fPIC.patch

Gentoo ships with a different approach, the attached patch is adding passing -fPIC and can be found at https://gitweb.gentoo.org/repo/gentoo.git/tree/app-text/ghostscript-gpl/files/ghostscript-gpl-10.06.0-tesseract-fPIC.patch