DanBloomberg / leptonica

Leptonica is an open source library containing software that is broadly useful for image processing and image analysis applications. The official github repository for Leptonica is: danbloomberg/leptonica. See leptonica.org for more documentation.
Other
1.79k stars 391 forks source link

Ghostscript build fails on Solaris due Tesseract and/or Leptonica #751

Closed l1gi closed 2 months ago

l1gi commented 2 months ago

Hello,

while trying to upgrade ghostscript-10.02.1 to ghostscript-10.03.1 on Solaris I have hit an issue with building tesseract which ghostscript bundles. I have created a bug report against ghostcript and against tesseract. It seems that the top level reason why it fails is a header file installed by leptonica, in particular environ.h.

As suggested in gs bug report I have tried to isolate the issue and found that I see the same behavior while building standalone tesseract.

tesseract-5.4.1$ gmake
Making all in .
gmake[1]: Entering directory '/scratch/userland-gate/components/ghostscript/tesseract-5.4.1'
  CXX      src/tesseract-tesseract.o
In file included from /usr/local/include/leptonica/alltypes.h:37,
                 from /usr/local/include/leptonica/allheaders.h:35,
                 from src/tesseract.cpp:34:
/usr/local/include/leptonica/environ.h:70:9: error: ‘atomic_int’ does not name a type
   70 | typedef atomic_int l_atomic;
      |         ^~~~~~~~~~
In file included from /usr/local/include/leptonica/alltypes.h:62:
/usr/local/include/leptonica/regutils.h:123:5: error: ‘l_atomic’ does not name a type
  123 |     l_atomic index;     /*!< index into saved files for this test; 0-based    */
      |     ^~~~~~~~
gmake[1]: *** [Makefile:7775: src/tesseract-tesseract.o] Error 1
gmake[1]: Leaving directory '/scratch/userland-gate/components/ghostscript/tesseract-5.4.1'
gmake: *** [Makefile:8156: all-recursive] Error 1

I can isolate the issue even further using Tessearct build system:

$ cat test.cpp
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__)
#include <stdatomic.h>
typedef atomic_int l_atomic;
#else
$ g++ -DHAVE_CONFIG_H   -O2 -DNDEBUG -I./include -I./include  -I./src/arch -I./src/ccmain -I./src/ccstruct -I./src/ccutil -I./src/classify -I./src/cutil -I./src/dict -I./src/textord -I./src/viewer -I./src/wordrec -I/usr/local/include/leptonica  -fopenmp -g -O2 -std=c++20 -MT src/tesseract-tesseract.o -MD -MP -MF src/.deps/tesseract-tesseract.Tpo -c -o src/tesseract-tesseract.o test.cpp
test.cpp:6:9: error: ‘atomic_int’   does not name a type
    6 | typedef atomic_int l_atomic;
      |         ^~~~~~~~~~

__STDC_VERSION__ is defined as 201112L, __STDC_NO_ATOMICS__ is not defined.

The platform in Solaris 11.4 with GCC:

$ uname -a
SunOS ST-ul-cbe 5.11 11.4.72.176.0 i86pc i386 i86pc virtualbox
$ g++ --version
g++ (GCC) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I guess the issue could be somewhere else (GCC?). It seems that there is something defined differently in comparison with Linux.

Could you help me find the root cause of the issue, please? Should you need any input, don't hesitate to ask.

Thank you in advance, Martin Rehak

stweil commented 2 months ago

Citing my answer from the still open Tesseract issue: "So you have to find out why on your Solaris system atomic_int is unknown although it claims to support atomics. I suggest to search all include paths for atomic_int."

Please don't open several issues in different repositories for the same issue.

amitdo commented 2 months ago

https://docs.oracle.com/cd/E60778_01/html/E60742/gqqkp.html

amitdo commented 2 months ago

I closed the Tesseract issue.

First, Tesseract does not officially support Solaris. Second, Tesseract is written in C++ and the issue is related to the C standard library in Solaris.

stweil commented 2 months ago

I close the Leptonica issue because the Leptonica build works, but add my solution for the Tesseract build there.