Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 784173

Summary: app-text/ghostscript-gpl fails to build with Clang/LLVM/LLD.
Product: Gentoo Linux Reporter: Alexander Julian Moch <gentoo>
Component: Current packagesAssignee: Codec Project <codec>
Severity: normal CC: marc_heimann, neotheuser, perfect007gentleman, printing, sam, sputnick
Priority: Normal Keywords: PATCH
Version: unspecified   
Hardware: All   
OS: Linux   
Package list:
Runtime testing required: ---
Bug Depends on:    
Bug Blocks: 408963, 836220    
Attachments: Output of `emerge --info`
`build.log` with Clang + LLD and LTO enabled
`build.log` with Clang + BFD without LTO
Patch for building with libc++

Description Alexander Julian Moch 2021-04-19 15:38:39 UTC
I'm using the entire LLVM toolchain v12.0.0 to build my packages. ghostscript-gpl fails with `ld.lld: error: undefined symbol: ...`. It works fine with GCC and Gold or BFD linker.

All undefined symbol errors are related to app-text/tesseract. Adding `--without-tesseract` to `src_configure()` fixes the problem and ghostscript-gpl builds without issue.

Here is one excerpt from the log file:

ld.lld: error: undefined symbol: std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream()
>>> referenced by altorenderer.cpp
>>>               ./obj/tesseract_api_altorenderer.o:(tesseract::TessBaseAPI::GetAltoText(tesseract::ETEXT_DESC*, int))
>>> referenced by baseapi.cpp
>>>               ./obj/tesseract_api_baseapi.o:(tesseract::TessBaseAPI::GetOsdText(int))
>>> referenced by hocrrenderer.cpp
>>>               ./obj/tesseract_api_hocrrenderer.o:(tesseract::TessBaseAPI::GetHOCRText(tesseract::ETEXT_DESC*, int))
>>> referenced 9 more times

Reproducible: Always
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2021-04-19 17:48:36 UTC
The full build.log and emerge —-info output is always needed. Could you provide that please?

Also, how about Clang with the normal GNU ld? ldd often exposes other issues unrelated to the compiler
Comment 2 Alexander Julian Moch 2021-04-19 18:13:02 UTC
Created attachment 700881 [details]
Output of `emerge --info`
Comment 3 Alexander Julian Moch 2021-04-19 18:15:35 UTC
Created attachment 700884 [details]
`build.log` with Clang + LLD and LTO enabled
Comment 4 Alexander Julian Moch 2021-04-19 18:16:18 UTC
Created attachment 700887 [details]
`build.log` with Clang + BFD without LTO
Comment 5 Alexander Julian Moch 2021-04-19 18:23:18 UTC
Sorry, in previous bug reports no one asked for `build.log` and the output of `emerge --info`. Now I included them.

The build process also fails when using Clang and BFD. Whether or not I enable LTO makes no difference.

app-text/tesseract is not installed and installing tesseract also did not fix the issue.
Comment 6 Perfect Gentleman 2021-05-14 16:22:13 UTC
confirm bug.
Adding `--without-tesseract' to EXTRA_ECONF solves it.
Comment 7 Thomas Deutschmann (RETIRED) gentoo-dev 2021-05-14 18:29:05 UTC
Note that app-text/ghostscript-gpl is bundling an own fork of tesseract since 9.53... so app-text/ghostscript-gpl does NOT use app-text/tesseract.

I personally do not care about Clang/LLVM/LLD at this point. Please report upstream and report back the link to their issue tracker. Also, patches are welcome.
Comment 8 Perfect Gentleman 2021-05-15 04:25:05 UTC
In Arch's PKGBUILD -
  # *** remove after final decision ***
  # new in 9.54.0: 

  # 1) inclusion of the tesseract/leptonica sources for OCR capabilities
  # at the moment we do not support linking with tesseract/leptonica shared libraries. 
  # As is normal with such included libraries, deleting those directories and (re)running
  # configure (on Unix like systems) will automatically build without the OCR functionality.
  # increases package size ghostpcl 2.7->4.9MB | ghostscript 18->23MB | ghostxps 2,7->4.9MB
  # - 
  # this doesn't seem to be worth to keep enabled until linking with shared libs is supported
  rm -r tesseract leptonica
Comment 9 Perfect Gentleman 2021-05-15 04:27:08 UTC
So, maybe just remove those directories as other internal copies ?
Comment 10 Paul Mulders 2021-11-23 18:15:04 UTC
do you have libcxx enabled? probably caused by it linking against libstdc++ instead of libc++. the invocation has "-lstdc++"
Comment 11 Alec Ari 2021-12-10 09:25:34 UTC
This is an actual bug. ghostscript-gpl hard-codes -lstdc++ and -stdlib=stdc++ in the Makefile, so having USE="libcxx" for sys-devel/clang doesn't actually do anything for this particular package. ghostscript-gpl should honor this but it doesn't.

I added a package.env conf file for it with the following:

CFLAGS="-O2 -stdlib=libc++ -fPIC -fstack-protector-strong -fstack-clash-protection -fomit-frame-pointer -pipe -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"

# ghostscript-gpl completely ignores CXXFLAGS
# -stdlib must actually be in CFLAGS
CXXFLAGS="-O2 -stdlib=libc++ -fPIC -fstack-protector-strong -fstack-clash-protection -fomit-frame-pointer -pipe -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2"

LDFLAGS="-Wl,-O1 -Wl,--as-needed -lc++ -fuse-ld=lld -Wl,-z,now -Wl,-z,relro -Wl,--strip-debug"

And the package built. The only relevant part for the bug is:

-stdlib=libc++ in CFLAGS
-lc++ in LDFLAGS.

Rest are all hardening flags, don't worry about that.
Comment 12 Manuel Nickschas 2022-04-13 23:14:23 UTC
Created attachment 770678 [details, diff]
Patch for building with libc++

I've been using this patch for a while to make ghostscript-gpl build with clang/libc++.
Comment 13 Larry the Git Cow gentoo-dev 2022-04-17 12:09:07 UTC
The bug has been closed via the following commit(s):

commit ab42ea869b7ed7f8739f3620728a4b5bddee68c9
Author:     Sam James <>
AuthorDate: 2022-04-17 11:03:53 +0000
Commit:     Sam James <>
CommitDate: 2022-04-17 12:08:58 +0000

    app-text/ghostscript-gpl: fix build w/ libcxx (don't force libstdc++)
    Signed-off-by: Sam James <>

 .../files/ghostscript-gpl-9.55.0-no-force-libstdcxx.patch    | 12 ++++++++++++
 app-text/ghostscript-gpl/ghostscript-gpl-9.55.0-r1.ebuild    |  6 +++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

Additionally, it has been referenced in the following commit(s):

commit 463ee510db265bbd373aadce60112eca3d062c8d
Author:     Sam James <>
AuthorDate: 2022-04-17 12:06:58 +0000
Commit:     Sam James <>
CommitDate: 2022-04-17 12:08:59 +0000

    app-text/ghostscript-gpl: add 9.56.1
    (Done the font bit anyway for 502566).
    Signed-off-by: Sam James <>

 app-text/ghostscript-gpl/Manifest                  |   2 +
 .../ghostscript-gpl/ghostscript-gpl-9.56.1.ebuild  | 180 +++++++++++++++++++++
 2 files changed, 182 insertions(+)