Failure to build on macOS when using Xcode 12.5 (12.4 works fine!)

1,110 views
Skip to first unread message

hamch...@gmail.com

unread,
Apr 30, 2021, 3:02:58 AM4/30/21
to tesseract-ocr
I've successfully built Tesseract for macOS (x86_64-apple-darwin) when using many versions of Xcode. However, the most recent version (12.5) is giving me issues when building.

I'm using the commit tagged 5.0.0-alpha-20210401 (bfe1616b4eef525e4fc30405fc41260f40ffee5e)

Here's the configure command I'm running (sorry for all the long paths):

export LIBS="-lz -lpng -ljpeg -ltiff -lwebp" ; \
export SDKROOT="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk" ; \
export CFLAGS="-I/Users/ham/projects/swift/Tesseract-OCR-iOS/TesseractOCR/tesseract-ocr/macos/x86_64-apple-darwin/include -L/Users/ham/projects/swift/Tesseract-OCR-iOS/TesseractOCR/macos/lib -Qunused-arguments -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -mmacosx-version-min="10.13" -O2 -fembed-bitcode" ; \
export CPPFLAGS="-I/Users/ham/projects/swift/Tesseract-OCR-iOS/TesseractOCR/tesseract-ocr/macos/x86_64-apple-darwin/include -L/Users/ham/projects/swift/Tesseract-OCR-iOS/TesseractOCR/macos/lib -Qunused-arguments -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -mmacosx-version-min=10.13 -O2 -fembed-bitcode -std=c++11 -I/Users/ham/projects/swift/Tesseract-OCR-iOS/TesseractOCR/leptonica/macos/x86_64-apple-darwin/include/leptonica" ; \
export CXXFLAGS="-I/Users/ham/projects/swift/Tesseract-OCR-iOS/TesseractOCR/tesseract-ocr/macos/x86_64-apple-darwin/include -L/Users/ham/projects/swift/Tesseract-OCR-iOS/TesseractOCR/macos/lib -Qunused-arguments -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -mmacosx-version-min="10.13" -O2 -Wno-deprecated-register -std=c++11"; \
export LDFLAGS="-L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/lib/ -L/Users/ham/projects/swift/Tesseract-OCR-iOS/TesseractOCR/leptonica/macos/x86_64-apple-darwin/src/.libs" ; \
export LIBLEPT_HEADERSDIR=/Users/ham/projects/swift/Tesseract-OCR-iOS/TesseractOCR/tesseract-ocr/macos/x86_64-apple-darwin/ ; \
export PKG_CONFIG_PATH=/Users/ham/projects/swift/Tesseract-OCR-iOS/TesseractOCR/leptonica/macos/x86_64-apple-darwin/ ; \
export CXX=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ ; \
mkdir -p /Users/ham/projects/swift/Tesseract-OCR-iOS/TesseractOCR/tesseract-ocr/macos/x86_64-apple-darwin ; \
cd /Users/ham/projects/swift/Tesseract-OCR-iOS/TesseractOCR/tesseract-ocr/macos/x86_64-apple-darwin ; \
ln -s /Users/ham/projects/swift/Tesseract-OCR-iOS/TesseractOCR/leptonica/src/ leptonica ; \
../../configure --host=x86_64-apple-darwin --prefix=`pwd`/output --enable-shared=no --disable-graphics --with-curl=no

This all works fine and I try and run the make command to build things and I end up with tons of errors. Here is a sample of them:

In file included from ../../src/arch/intsimdmatrixsse.cpp:24:

In file included from ../../src/arch/intsimdmatrix.h:24:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/vector:276:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/__bit_reference:14:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/bit:58:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/limits:105:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/type_traits:417:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/cstddef:37:

../../version:1:1: error: expected unqualified-id

5.0.0-alpha-20210401

^

In file included from ../../src/arch/intsimdmatrixavx2.cpp:24:

In file included from ../../src/arch/intsimdmatrix.h:24:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/vector:276:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/__bit_reference:14:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/bit:58:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/limits:105:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/type_traits:417:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/incIn file included from ../../src/arch/intsimdmatrixsse.cpp:24:

In file included from ../../src/arch/intsimdmatrix.h:24:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/vector:276:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/__bit_reference:14:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/bit:58:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/limits:105:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/type_traits:418:

../../version:1:1: error: expected unqualified-id

5.0.0-alpha-20210401

^

lude/c++/v1/cstddef:37:

../../version:1:1: error: expected unqualified-id

5.0.0-alpha-20210401

^

In file included from ../../include/tesseract/unichar.h:26:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/string:506:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/string_view:175:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/__string:57:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/algorithm:639:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/initializer_list:46:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/cstddef:49:9: error: no member named 'ptrdiff_t' in the global namespace

using ::ptrdiff_t;

      ~~^

In file included from ../../src/api/altorenderer.cpp:20:

In file included from ../../include/tesseract/baseapi.h:29:

In file included from ../../include/tesseract/resultiterator.h:25:

In file included from ../../include/tesseract/ltrresultiterator.h:26:

In file included from ../../include/tesseract/unichar.h:26:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/string:506:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/string_view:175:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/__string:57:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/algorithm:643:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/memory:674:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/iterator:562:13: error: unknown type name 'ptrdiff_t'

    typedef ptrdiff_t difference_type;

            ^

In file included from ../../src/api/baseapi.cpp:26:

In file included from ../../src/ccstruct/boxword.h:22:

In file included from ../../src/ccstruct/rect.h:22:

In file included from ../../src/ccstruct/points.h:22:

In file included from ../../src/ccutil/elst.h:24:

In file included from ../../src/ccutil/serialis.h:22:

In file included from ../../include/tesseract/baseapi.h:29:

In file included from ../../include/tesseract/resultiterator.h:25:

In file included from ../../include/tesseract/ltrresultiterator.h:26:

In file included from ../../include/tesseract/unichar.h:26:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/string:506:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/string_view:175:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/__string:57:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/algorithm:643:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/memory:674:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/include/c++/v1/iterator:562:13: error: unknown type name 'ptrdiff_t'

    typedef ptrdiff_t difference_type;



This exact setup works fine if I change the version of Xcode I have active to be 12.4 (the previous version).

As far as I can tell the only difference between the two build setups is the value that gets set for SDKROOT.

For Xcode 12.5: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk


In terms of differences inside those directories, they look incredibly similar,. apart from the fact that inside the Xcode 12.5 SDK root's /usr/include directory there is a c++/v1 directory that contains a load of C++ headers, listed here: 

__bit_reference, __tree, clocale, cwctype, istream, regex, system_error, __bsd_locale_defaults.h__tuple, cmath, cxxabi.h, iterator, scoped_allocator, tgmath.h, __bsd_locale_fallbacks.h__undef_macros, codecvt, deque, latch, semaphore, thread, __config, algorithm, compare, errno.h, limits, set, tuple, __cxxabi_config.hany, complex, exception, limits.h, setjmp.h, type_traits, __debug, array, complex.h, execution, list, shared_mutex, typeindex, __errc, atomic, concepts, experimental, locale, span, typeinfo, __functional_03, barrier, condition_variableext, locale.h, sstream, unordered_map, __functional_basebit, csetjmp, fenv.h, map, stack, unordered_set, __functional_base_03bitset, csignal, filesystem, math.h, stdbool.h, utility, __hash_table, cassert, cstdarg, float.h, memory, stddef.h, valarray, __libcpp_version, ccomplex, cstdbool, forward_list, module.modulemapstd, except, variant, __locale, cctype, cstddef, fstream, mutex, stdint.h, vector, __mutex_base, cerrno, cstdint, functional, new, stdio.h, version, __node_handle, cfenv, cstdio, future, numbers, stdlib.h, wchar.h, __nullptr, cfloat, cstdlib, initializer_listnumeric, streambuf, wctype.h, __split_buffer, charconv, cstring, inttypes.h, optional, string, __sso_allocator, chrono, ctgmath, iomanip, ostream, string.h, __std_stream, cinttypes, ctime, ios, queue, string_view, __string, ciso646, ctype.h, iosfwd, random, strstream, __threading_support, climits, cwchar, iostream, ratio, support

Has anyone run into errors like this and knows how to fix them?

They look like I might be running into a C++ version mismatch or something similar but I've tried editing the Makefile to explicitly set -std=c++11, -std=c++14, -std=c++17, and -std=c++20, and none seem to make things work.

Thanks!

hamch...@gmail.com

unread,
Apr 30, 2021, 5:16:08 PM4/30/21
to tesseract-ocr
Okay I've debugged this further and figured out what the root cause if, but don't really have a satisfying solution.

Essentially, what seems to be going on is when the cstddef header is #include-ed it has a line in it that does #include <version> (see here: https://github.com/llvm/llvm-project/blob/2cd78686055f1badb9aa55cb95e189548ffc82f0/libcxx/include/cstddef#L37). This should be including this header: https://github.com/llvm/llvm-project/blob/main/libcxx/include/version

However, what ends up being included instead if the VERSION file at the root of the tesseract repo: https://github.com/tesseract-ocr/tesseract/blob/master/VERSION

I don't understand why that file is being found by the compiler though. I don't seem to have any -I flags being passed in that set the root of the tesseract repo as a directory to search for headers. 

Anyone with any ideas as to what's going on? Is it because of the version in #include <version> being in angled brackets instead of quotes meaning that it searches at the same directory as the configure file is in for a file named version, and macOS is case insensitive so it finds the VERSION at the root of the repo?

In any case, if I change the name of the VERSION file to something like TESS_VERSION and update configure.ac to reference that new name (TESS_VERSION) instead, then things build successfully. (The relevant line in configure.ac is this one: https://github.com/tesseract-ocr/tesseract/blob/a9682bb6e2c32797f455c95de66ea87e00624dbe/configure.ac#L10)
Reply all
Reply to author
Forward
0 new messages