Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake currently does not support Tesseract builds for non Intel hosts (Android cross-build error) #2337

Closed
Bleach665 opened this issue Mar 19, 2019 · 34 comments

Comments

@Bleach665
Copy link

Host OS: Linux xubuntu64 4.15.0-33-generic #36-Ubuntu SMP Wed Aug 15 16:00:05 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux; CMake GUI 3.10.2; Android toolchain - android-ndk-r15c; gcc version 7.3.0; Tesseract rev. ac7ea43.
CMake GUI changes: CMAKE_PREFIX_PATH:PATH="/home/bleach/Lib/leptonica/build_arm" specified.
Build error received:

make output
/home/bleach/Lib/tesseract/source/src/arch/dotproductavx.cpp:20:2: error: Implementation only for AVX capable architectures
#error Implementation only for AVX capable architectures
 ^
In file included from /home/bleach/Lib/tesseract/source/src/arch/dotproductavx.cpp:23:
In file included from /home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/immintrin.h:28:
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:47:5: error: use of undeclared identifier '__builtin_ia32_emms'; did you mean
      '__builtin_isless'?
    __builtin_ia32_emms();
    ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:47:5: note: '__builtin_isless' declared here
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:47:25: error: too few arguments to function call, expected 2, have 0
    __builtin_ia32_emms();
                        ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:64:19: error: use of undeclared identifier '__builtin_ia32_vec_init_v2si'
    return (__m64)__builtin_ia32_vec_init_v2si(__i, 0);
                  ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:81:12: error: use of undeclared identifier '__builtin_ia32_vec_ext_v2si'
    return __builtin_ia32_vec_ext_v2si((__v2si)__m, 0);
           ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:143:19: error: use of undeclared identifier '__builtin_ia32_packsswb'
    return (__m64)__builtin_ia32_packsswb((__v4hi)__m1, (__v4hi)__m2);
                  ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:173:19: error: use of undeclared identifier '__builtin_ia32_packssdw'
    return (__m64)__builtin_ia32_packssdw((__v2si)__m1, (__v2si)__m2);
                  ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:203:19: error: use of undeclared identifier '__builtin_ia32_packuswb'
    return (__m64)__builtin_ia32_packuswb((__v4hi)__m1, (__v4hi)__m2);
                  ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:230:19: error: use of undeclared identifier '__builtin_ia32_punpckhbw'
    return (__m64)__builtin_ia32_punpckhbw((__v8qi)__m1, (__v8qi)__m2);
                  ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:253:19: error: use of undeclared identifier '__builtin_ia32_punpckhwd'
    return (__m64)__builtin_ia32_punpckhwd((__v4hi)__m1, (__v4hi)__m2);
                  ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:274:19: error: use of undeclared identifier '__builtin_ia32_punpckhdq'
    return (__m64)__builtin_ia32_punpckhdq((__v2si)__m1, (__v2si)__m2);
                  ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:301:19: error: use of undeclared identifier '__builtin_ia32_punpcklbw'
    return (__m64)__builtin_ia32_punpcklbw((__v8qi)__m1, (__v8qi)__m2);
                  ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:324:19: error: use of undeclared identifier '__builtin_ia32_punpcklwd'
    return (__m64)__builtin_ia32_punpcklwd((__v4hi)__m1, (__v4hi)__m2);
                  ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:345:19: error: use of undeclared identifier '__builtin_ia32_punpckldq'
    return (__m64)__builtin_ia32_punpckldq((__v2si)__m1, (__v2si)__m2);
                  ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:366:19: error: use of undeclared identifier '__builtin_ia32_paddb'; did you mean
      '__builtin_arm_qadd'?
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                  ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:366:19: note: '__builtin_arm_qadd' declared here
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:366:40: error: cannot initialize a parameter of type 'int' with an rvalue of type
      '__v8qi' (vector of 8 'char' values)
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                                       ^~~~~~~~~~~~
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:387:19: error: use of undeclared identifier '__builtin_ia32_paddw'; did you mean
      '__builtin_arm_qadd'?
    return (__m64)__builtin_ia32_paddw((__v4hi)__m1, (__v4hi)__m2);
                  ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:366:19: note: '__builtin_arm_qadd' declared here
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                  ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:387:40: error: cannot initialize a parameter of type 'int' with an rvalue of type
      '__v4hi' (vector of 4 'short' values)
    return (__m64)__builtin_ia32_paddw((__v4hi)__m1, (__v4hi)__m2);
                                       ^~~~~~~~~~~~
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:408:19: error: use of undeclared identifier '__builtin_ia32_paddd'; did you mean
      '__builtin_arm_qadd'?
    return (__m64)__builtin_ia32_paddd((__v2si)__m1, (__v2si)__m2);
                  ^
/home/bleach/Lib/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/5.0.300080/include/mmintrin.h:366:19: note: '__builtin_arm_qadd' declared here
    return (__m64)__builtin_ia32_paddb((__v8qi)__m1, (__v8qi)__m2);
                  ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
CMakeFiles/libtesseract.dir/build.make:86: recipe for target 'CMakeFiles/libtesseract.dir/src/arch/dotproductavx.cpp.o' failed
make[2]: *** [CMakeFiles/libtesseract.dir/src/arch/dotproductavx.cpp.o] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/libtesseract.dir/all' failed
make[1]: *** [CMakeFiles/libtesseract.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

Please advise how to quickly remove AVX(2) support from the code or Cmake config. I tried

my changes
index ef5d1b47..3afc4275 100644
@@ -117,14 +117,14 @@ AM_CONDITIONAL([AVX2_OPT], false)
 AM_CONDITIONAL([SSE41_OPT], false)
 AM_CONDITIONAL([MARCH_NATIVE_OPT], false)
 
-AX_CHECK_COMPILE_FLAG([-mavx], [avx=true], [avx=false])
+AX_CHECK_COMPILE_FLAG([-mavx], [avx=false], [avx=false])
 if $avx; then
-    AM_CONDITIONAL([AVX_OPT], true)
+    AM_CONDITIONAL([AVX_OPT], false)
 fi
 
-AX_CHECK_COMPILE_FLAG([-mavx2], [avx2=true], [avx2=false])
+AX_CHECK_COMPILE_FLAG([-mavx2], [avx2=false], [avx2=false])
 if $avx2; then
-    AM_CONDITIONAL([AVX2_OPT], true)
+    AM_CONDITIONAL([AVX2_OPT], false)
 fi
 
 AX_CHECK_COMPILE_FLAG([-msse4.1], [sse41=true], [sse41=false])

---------------------------- src/arch/simddetect.h ----------------------------
index def66896..c137e118 100644
@@ -31,12 +31,12 @@ extern DotProductFunction DotProduct;
 class SIMDDetect {
  public:
   // Returns true if AVX is available on this system.
-  static inline bool IsAVXAvailable() { return detector.avx_available_; }
+  static inline bool IsAVXAvailable() { return false; }
   // Returns true if AVX2 (integer support) is available on this system.
-  static inline bool IsAVX2Available() { return detector.avx2_available_; }
+  static inline bool IsAVX2Available() { return false; }
   // Returns true if AVX512 Foundation (float) is available on this system.
   static inline bool IsAVX512FAvailable() {
-    return detector.avx512F_available_;
+    return false;
   }
   // Returns true if AVX512 integer is available on this system.
   static inline bool IsAVX512BWAvailable() {
, but it did not help.
@stweil
Copy link
Member

stweil commented Mar 19, 2019

Is this a duplicate of issue #2334? All errors shown in your make output are in files which are not part of the Tesseract sources. Those files obviously are for the Intel architecture, so they should not be included by ARM toolchains. This looks like a wrong build setting.

I don't know whether the CMake build settings work for non Intel architectures. I know that the autoconf based build works, so please use that.

@zdenop
Copy link
Contributor

zdenop commented Mar 19, 2019

@stweil: this is cmake related related issue and 2334 is autotools related, so from perspective of build tools it is not duplicate.
I am not sure if our current cmake configuration will work for android build without modification, but just setting CMAKE_PREFIX_PATH seems to be not sufficient...

@stweil
Copy link
Member

stweil commented Mar 19, 2019

Thank you, @zdenop. Yes, the current CMake has fixed unconditional settings for Intel builds and cannot support cross builds for other architectures like ARM. I update the summary.

@stweil stweil changed the title Android cross-build error, AVX CMake currently does not support Tesseract builds for non Intel hosts (Android cross-build error) Mar 19, 2019
@stweil stweil added bug and removed question labels Mar 19, 2019
@zdenop
Copy link
Contributor

zdenop commented Apr 22, 2019

@Bleach665 : try current master - there is detection of available features in cmake.

@Bleach665
Copy link
Author

Bleach665 commented Apr 22, 2019

@zdenop.
I do not have at fingertips Linux, therefore I try to build in Windows 10.
I configure Tesseract via CMake with Android 16 toolchain and MinGW makefile. MinGW was taken from Qt distrib.
Leptonica configured in such way was build successfully. Tesseract CMake configuration performed well (with minimal changes CMakeList.txt), but on build I receive errors:

Scanning dependencies of target libtesseract
[  0%] Building CXX object CMakeFiles/libtesseract.dir/src/arch/dotproduct.cpp.o
[  0%] Building CXX object CMakeFiles/libtesseract.dir/src/arch/intsimdmatrix.cpp.o
[  1%] Building CXX object CMakeFiles/libtesseract.dir/src/arch/simddetect.cpp.o
[  1%] Building CXX object CMakeFiles/libtesseract.dir/src/ccmain/adaptions.cpp.o
In file included from E:\Lib_prebuild\tesseract\source\src\ccmain\adaptions.cpp:26:
E:\Lib_prebuild\tesseract\source\src\ccmain/tesseractclass.h:30:10: fatal error: 'allheaders.h' file not found
#include "allheaders.h"             // for pixDestroy, pixGetWidth, pixGetHe...
         ^~~~~~~~~~~~~~
1 error generated.
CMakeFiles\libtesseract.dir\build.make:100: recipe for target 'CMakeFiles/libtesseract.dir/src/ccmain/adaptions.cpp.o' failed
mingw32-make[2]: *** [CMakeFiles/libtesseract.dir/src/ccmain/adaptions.cpp.o] Error 1
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/libtesseract.dir/all' failed
mingw32-make[1]: *** [CMakeFiles/libtesseract.dir/all] Error 2
Makefile:128: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

PS. CMakeList.txt changes to perform Windows build:
if(NOT CPPAN_BUILD)
'-' if (NOT Leptonica_DIR AND NOT MSVC)
'+' if (NOT Leptonica_DIR AND NOT MSVC AND COMMAND pkg_check_modules)
find_package(PkgConfig REQUIRED)
pkg_check_modules(Leptonica REQUIRED lept>=${MINIMUM_LEPTONICA_VERSION})
link_directories(${Leptonica_LIBRARY_DIRS})

@zdenop
Copy link
Contributor

zdenop commented Apr 22, 2019 via email

@Bleach665
Copy link
Author

Bleach665 commented Apr 22, 2019

Just run path-to\mingw32-make.exe in CMake build directory.
UPD. I found the problem - this is my configuration error..
Now we have next errors:

[ 18%] Building CXX object CMakeFiles/libtesseract.dir/src/ccutil/ccutil.cpp.o
[ 18%] Building CXX object CMakeFiles/libtesseract.dir/src/ccutil/clst.cpp.o
[ 18%] Building CXX object CMakeFiles/libtesseract.dir/src/ccutil/elst.cpp.o
[ 19%] Building CXX object CMakeFiles/libtesseract.dir/src/ccutil/elst2.cpp.o
[ 19%] Building CXX object CMakeFiles/libtesseract.dir/src/ccutil/errcode.cpp.o
[ 20%] Building CXX object CMakeFiles/libtesseract.dir/src/ccutil/fileio.cpp.o
E:\Lib_prebuild\tesseract\source\src\ccutil\fileio.cpp:121:7: error: use of undeclared identifier 'glob'
  if (glob(pattern, 0, nullptr, &pglob) == 0) {
      ^
E:\Lib_prebuild\tesseract\source\src\ccutil\fileio.cpp:125:5: error: use of undeclared identifier 'globfree'
    globfree(&pglob);
    ^
2 errors generated.
CMakeFiles\libtesseract.dir\build.make:1088: recipe for target 'CMakeFiles/libtesseract.dir/src/ccutil/fileio.cpp.o' failed
mingw32-make[2]: *** [CMakeFiles/libtesseract.dir/src/ccutil/fileio.cpp.o] Error 1
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/libtesseract.dir/all' failed
mingw32-make[1]: *** [CMakeFiles/libtesseract.dir/all] Error 2
Makefile:128: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

@zdenop
Copy link
Contributor

zdenop commented Apr 22, 2019 via email

@Bleach665
Copy link
Author

Oh, I did not read carefully. I wrote a little of text, maybe it would helpfully to draw up instruction in future.
CMake GUI was used. After 'configure' button was pressed next parameters were specified:
Specify the generator for this project - MinGW Makefile
Specify toolchain file for cross-compiling was selected
qqq1
On the next page toolchain file was specified.
qqq2
In my case CMAKE_SH was defined, because msys64\usr was in my PATH envinronment variable. So we undefine it to perform success configure.
After that we need to specify CMAKE_MAKE_PROGRAM with mingw32-make.exe path. MinGW was taken from Qt distribution.
qqq3

Configure button pressed again.
Next, let's point out the path to Leptonica - Leptonica_DIR must point to Leptonica install CMake folder.
Configure, Generate.
Open command prompt, go to CMake configure output folder. Type path-to-mingw\mingw32-make.exe install.
Done.

@Bleach665
Copy link
Author

In xubuntux64 I receive same error:

[ 32%] Building CXX object CMakeFiles/libtesseract.dir/src/ccutil/elst2.cpp.o
[ 32%] Building CXX object CMakeFiles/libtesseract.dir/src/ccutil/errcode.cpp.o
[ 33%] Building CXX object CMakeFiles/libtesseract.dir/src/ccutil/fileio.cpp.o
/home/bleach/Lib/Tesseract/source/src/ccutil/fileio.cpp:23:10: fatal error: 'glob.h' file not found
#include <glob.h>
         ^~~~~~~~
1 error generated.
CMakeFiles/libtesseract.dir/build.make:1958: recipe for target 'CMakeFiles/libtesseract.dir/src/ccutil/fileio.cpp.o' failed
make[2]: *** [CMakeFiles/libtesseract.dir/src/ccutil/fileio.cpp.o] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/libtesseract.dir/all' failed
make[1]: *** [CMakeFiles/libtesseract.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

@Shreeshrii
Copy link
Collaborator

Configure button pressed again.
Next, let's point out the path to Leptonica - Leptonica_DIR must point to Leptonica install CMake folder.
Configure, Generate.
Open command prompt, go to CMake configure output folder. Type path-to-mingw\mingw32-make.exe install.
Done.

Are you building leptonica after tesseract?

You need to build it before.

@Bleach665
Copy link
Author

Bleach665 commented Apr 22, 2019

Leptonica was build before Tesseract. As far as I remember in CMakeList.txt Leptonica find_package is with REQUIRED flag, so Leptonica_DIR should point to right dir (cmake dir in our install dir), if not then we get an error while configuring. At least in Windows so.

And, maybe that's important, TARGET_ARCHITECTURE in CMake was set to armeabi-v7a.

@zdenop
Copy link
Contributor

zdenop commented Apr 23, 2019

@Bleach665 : glob.h is provided by os (linux or android) so this is not tesseract issue anymore. Seems like you need to setup include path for cmake, so compiler finds all needed system header files.

@Bleach665
Copy link
Author

Bleach665 commented Apr 24, 2019

@zdenop . Yes,

if(ANDROID_TOOLCHAIN)
include_directories(${ANDROID_TOOLCHAIN}/sysroot/usr/include)
endif()

added to CMake config file fix it.
But after fix we have another error:

[ 19%] Building CXX object CMakeFiles/libtesseract.dir/src/ccutil/errcode.cpp.o
[ 20%] Building CXX object CMakeFiles/libtesseract.dir/src/ccutil/fileio.cpp.o
E:\Lib_prebuild\tesseract\source\src\ccutil\fileio.cpp:121:7: error: use of undeclared identifier 'glob'
  if (glob(pattern, 0, nullptr, &pglob) == 0) {
      ^
E:\Lib_prebuild\tesseract\source\src\ccutil\fileio.cpp:125:5: error: use of undeclared identifier 'globfree'
    globfree(&pglob);
    ^
2 errors generated.
CMakeFiles\libtesseract.dir\build.make:1088: recipe for target 'CMakeFiles/libtesseract.dir/src/ccutil/fileio.cpp.o' failed
mingw32-make[2]: *** [CMakeFiles/libtesseract.dir/src/ccutil/fileio.cpp.o] Error 1
CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/libtesseract.dir/all' failed
mingw32-make[1]: *** [CMakeFiles/libtesseract.dir/all] Error 2
Makefile:128: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

UPD.
It appear because in glob.h

#if __ANDROID_API__ >= __ANDROID_API_FUTURE__
int glob(const char* __pattern, int __flags, int (*__error_callback)(const char* __failure_path, int __failure_errno), glob_t* __result_ptr) __INTRODUCED_IN_FUTURE;
void globfree(glob_t* __result_ptr) __INTRODUCED_IN_FUTURE;
#endif /* __ANDROID_API__ >= __ANDROID_API_FUTURE__ */

at the time of compilation
__ANDROID_API__ =14 and
__ANDROID_API_FUTURE__ = 10000.

__ANDROID_API_FUTURE__ defined in NDK_DIR\sysroot\usr\include\android\api-level.h :

#ifndef __ANDROID_API_FUTURE__
#define __ANDROID_API_FUTURE__ 10000
#endif

Does anyone know how __ANDROID_API_FUTURE__ is initialized during the configuration?

@zdenop
Copy link
Contributor

zdenop commented Apr 24, 2019

Sorry, but this is not tesseract related. You should go to some android forum.

@Bleach665
Copy link
Author

Bleach665 commented Apr 24, 2019

Ok. Recent changes to make worked solution.
Only for testing i directly define __ANDROID_API_FUTURE__:
add_compile_definitions(__ANDROID_API_FUTURE__) added to CMake config file.

So, with all of the above described changes we have successful CMake configuration and build for Android cross build in Widows using android NDK toolchain and MinGW32.
Patch:
0001-fix-Android-cross-build-in-Windows-and-Linux.zip
Please note that minimal version NDK is r16b.

@zdenop zdenop closed this as completed in 0fe9290 Apr 24, 2019
@zdenop
Copy link
Contributor

zdenop commented Apr 24, 2019

thanks

@ismail
Copy link
Contributor

ismail commented Apr 29, 2019

This breaks the normal Linux build:

CMake Error at CMakeLists.txt:151 (find_package):
  Could not find a package configuration file provided by "Leptonica"
  (requested version 1.74) with any of the following names:

    LeptonicaConfig.cmake
    leptonica-config.cmake

  Add the installation prefix of "Leptonica" to CMAKE_PREFIX_PATH or set
  "Leptonica_DIR" to a directory containing one of the above files.  If
  "Leptonica" provides a separate development package or SDK, be sure it has
  been installed.

This is because

-    if (NOT Leptonica_DIR AND NOT MSVC)
+    if (NOT Leptonica_DIR AND NOT MSVC AND COMMAND pkg_check_modules)

checks for pkg_check_modules but this function is not defined until you require PkgConfig hence creating a chicken-egg problem.

@zdenop
Copy link
Contributor

zdenop commented Apr 29, 2019

thanks for report. should be fixed.

stweil pushed a commit to stweil/tesseract that referenced this issue May 1, 2019
stweil pushed a commit that referenced this issue May 1, 2019
@gorankarlic
Copy link

gorankarlic commented May 6, 2019

Commit 0fe9290 actually fixed cmake based build on macOS, which I could not make work otherwise (missing -lleptonica although libleptonica present in /usr/local/lib). d5f23a6 087576f makes it fail again.

@zdenop
Copy link
Contributor

zdenop commented May 6, 2019

What is error message?

@gorankarlic
Copy link

gorankarlic commented May 6, 2019

d5f23a6 actually works on MacOS 10.14.4

git clone https://github.com/tesseract-ocr/tesseract.git
cd tesseract
git reset --hard d5f23a61b36de564c660ce37fec28bbc2b58f1e1
mkdir build && cd build
cmake ..
make -j8
...
[100%] Built target tesseract

087576f fails (and 7a5b9b8 behaves exactly the same way)

git clone https://github.com/tesseract-ocr/tesseract.git
git reset --hard 087576f2d9d320cff5ba41df29120a8d8cc0e08b
cd tesseract
mkdir build && cd build
cmake ..
...
Configuring tesseract version 5.0.0-alpha-45-g7a5b...
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) 
CMake Error at CMakeLists.txt:149 (message):
  Missing required pkg-config


-- Configuring incomplete, errors occurred!

Although which pkgconf outputs /usr/local/bin/pkgconf - but this error is fixable by specifying the pkgconf path explicitly:

cmake .. -D PKG_CONFIG_EXECUTABLE=/usr/local/bin/pkgconf
make -j8
...
[ 99%] Linking CXX shared library libtesseract.dylib
ld: library not found for -lleptonica
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libtesseract.5.0.0.dylib] Error 1
make[1]: *** [CMakeFiles/libtesseract.dir/all] Error 2
make: *** [all] Error 2

Altough Leptonica is present in /usr/local/lib:

ls /usr/local/lib/liblept*
/usr/local/lib/liblept.dylib -> libleptonica.1.79.0.dylib
/usr/local/lib/libleptonica.1.79.0.dylib
/usr/local/lib/libleptonica.5.3.0.dylib -> libleptonica.1.79.0.dylib
/usr/local/lib/libleptonica.dylib -> libleptonica.5.3.0.dylib

Thanks for the quick reply.

@zdenop
Copy link
Contributor

zdenop commented May 7, 2019

How did you install leptonica? Leptonica cmake build also requires pkg-config.

@gorankarlic
Copy link

Leptonica seems to be able compile even without pkgconfig:

git clone https://github.com/DanBloomberg/leptonica.git
cd leptonica && mkdir build && cd build
cmake ..
...
-- Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)
...
-- Generating done

Makefile is created and make works just fine.

My approach is a bit unusual, as I am compiling everything from source, as most users seem to install it using brew or port.

@zdenop
Copy link
Contributor

zdenop commented May 8, 2019

@Bleach665: can you please test the latest code if it works for you?

@Bleach665
Copy link
Author

Bleach665 commented May 10, 2019

@zdenop. I will be able to do it from the middle of next week. (Cross-platform arm7 build, using CMake with mingw32 in Windows)
UPD. But now I test latest code (rev. 3f4dcf3) with CMake GUI 3.8.2 in Windows 10 x86(!) and get configuration error:

CMake GUI output
fatal: Not a git repository (or any of the parent directories): .git

Configuring tesseract version 5.0.0-alpha...
CMake Error at CMakeLists.txt:165 (add_subdirectory):
  add_subdirectory given source ".cppan" which is not an existing directory.


Could NOT find LibArchive (missing:  LibArchive_LIBRARY LibArchive_INCLUDE_DIR) 
target changed from "" to "auto"
Detected CPU: core
Performing Test check_cxx_compiler_flag__arch_SSE2
Performing Test check_cxx_compiler_flag__arch_SSE2 - Success
Performing Test COMPILER_SUPPORTS_MARCH_NATIVE
Performing Test COMPILER_SUPPORTS_MARCH_NATIVE - Failed
Looking for include file dlfcn.h
Looking for include file dlfcn.h - not found
Looking for include file inttypes.h
Looking for include file inttypes.h - found
Looking for include file limits.h
Looking for include file limits.h - found
Looking for include file malloc.h
Looking for include file malloc.h - found
Looking for include file memory.h
Looking for include file memory.h - found
Looking for include file stdbool.h
Looking for include file stdbool.h - found
Looking for include file stdint.h
Looking for include file stdint.h - found
Looking for include file stdlib.h
Looking for include file stdlib.h - found
Looking for include file string.h
Looking for include file string.h - found
Looking for include file sys/ipc.h
Looking for include file sys/ipc.h - not found
Looking for include file sys/shm.h
Looking for include file sys/shm.h - not found
Looking for include file sys/stat.h
Looking for include file sys/stat.h - found
Looking for include file sys/types.h
Looking for include file sys/types.h - found
Looking for include file sys/wait.h
Looking for include file sys/wait.h - not found
Looking for include file unistd.h
Looking for include file unistd.h - not found
Looking for include file cairo/cairo-version.h
Looking for include file cairo/cairo-version.h - not found
Looking for include file CL/cl.h
Looking for include file CL/cl.h - not found
Looking for include file OpenCL/cl.h
Looking for include file OpenCL/cl.h - not found
Looking for include file pango-1.0/pango/pango-features.h
Looking for include file pango-1.0/pango/pango-features.h - not found
Looking for include file tiffio.h
Looking for include file tiffio.h - not found
Looking for include file unicode/uchar.h
Looking for include file unicode/uchar.h - not found
Looking for stddef.h
Looking for stddef.h - found
Check size of long long int
Check size of long long int - done
Check size of off_t
Check size of off_t - done
Check size of mbstate_t
Check size of mbstate_t - done
Check size of wchar_t
Check size of wchar_t - done
Check size of _Bool
Check size of _Bool - done
Check if the system is big endian
Searching 16 bit integer
Check size of unsigned short
Check size of unsigned short - done
Using unsigned short
Check if the system is big endian - little endian

General configuration for Tesseract 5.0.0-alpha
--------------------------------------------------------
Build type: 
Compiler: MSVC
Used standard: C++14
CXX compiler options:  /DWIN32 /D_WINDOWS /W3 /GR /EHsc /utf-8 /MP /arch:SSE2
Linker options: /machine:X86 
Install directory: C:/Program Files/tesseract
Architecture flags: /arch:SSE2
Vector unit list: sse2;sse3
AVX_OPT: OFF
AVX2_OPT: OFF
SSE41_OPT: OFF
MARCH_NATIVE_OPT: OFF
sim_flags:  -DSSE2 -DSSE3

Build with cppan [CPPAN_BUILD]: OFF
Build with openmp support [OPENMP_BUILD]: OFF
Disable disable graphics (ScrollView) [GRAPHICS_DISABLED]: OFF
Enable embedded build [EMBEDDED]: OFF
Disable the legacy OCR engine [DISABLED_LEGACY_ENGINE]: OFF
Build training tools [BUILD_TRAINING_TOOLS]: ON
Build tests [BUILD_TESTS]: OFF
--------------------------------------------------------

Check size of void *
Check size of void * - done
Downloading latest ICU binaries
[download 0% complete]
[download 1% complete]
[download 2% complete]
[download 3% complete]
[download 4% complete]
[download 5% complete]
[download 6% complete]
[download 7% complete]
[download 8% complete]
[download 9% complete]
[download 10% complete]
[download 11% complete]
[download 12% complete]
[download 13% complete]
[download 14% complete]
[download 15% complete]
[download 16% complete]
[download 17% complete]
[download 18% complete]
[download 19% complete]
[download 20% complete]
[download 21% complete]
[download 22% complete]
[download 23% complete]
[download 24% complete]
[download 25% complete]
[download 26% complete]
[download 27% complete]
[download 28% complete]
[download 29% complete]
[download 30% complete]
[download 31% complete]
[download 32% complete]
[download 33% complete]
[download 34% complete]
[download 35% complete]
[download 36% complete]
[download 37% complete]
[download 38% complete]
[download 39% complete]
[download 40% complete]
[download 41% complete]
[download 42% complete]
[download 43% complete]
[download 44% complete]
[download 45% complete]
[download 46% complete]
[download 47% complete]
[download 48% complete]
[download 49% complete]
[download 50% complete]
[download 51% complete]
[download 52% complete]
[download 53% complete]
[download 54% complete]
[download 55% complete]
[download 56% complete]
[download 57% complete]
[download 58% complete]
[download 59% complete]
[download 60% complete]
[download 61% complete]
[download 62% complete]
[download 63% complete]
[download 64% complete]
[download 65% complete]
[download 66% complete]
[download 67% complete]
[download 68% complete]
[download 69% complete]
[download 70% complete]
[download 71% complete]
[download 72% complete]
[download 73% complete]
[download 74% complete]
[download 75% complete]
[download 76% complete]
[download 77% complete]
[download 78% complete]
[download 79% complete]
[download 80% complete]
[download 81% complete]
[download 82% complete]
[download 83% complete]
[download 84% complete]
[download 85% complete]
[download 86% complete]
[download 87% complete]
[download 88% complete]
[download 89% complete]
[download 90% complete]
[download 91% complete]
[download 92% complete]
[download 93% complete]
[download 94% complete]
[download 95% complete]
[download 96% complete]
[download 97% complete]
[download 98% complete]
[download 99% complete]
[download 100% complete]
Found the following ICU libraries:
  uc (required)
  i18n (required)
Found ICU: E:/Lib_prebuild/tesseract/prebuild_x86_1/src/training/icu/icu/include (found version "56.1") 
Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE) 
Configuring incomplete, errors occurred!
See also "E:/Lib_prebuild/tesseract/prebuild_x86_1/CMakeFiles/CMakeOutput.log".
See also "E:/Lib_prebuild/tesseract/prebuild_x86_1/CMakeFiles/CMakeError.log".

CMake changes:

Commandline options:
-DLeptonica_DIR:PATH="E:/Lib_prebuild/leptonica/build_x86/cmake" 

@Bleach665
Copy link
Author

@zdenop. I try perform cross build in Windows 10, mingw32, CMake 3.13.4, android ndk r16b (a few commits ago build with this configuration was successful) and get CMake configuration error:

CMake gui output:
fatal: not a git repository (or any of the parent directories): .git

Configuring tesseract version 5.0.0-alpha...
CMake Error at CMakeLists.txt:165 (add_subdirectory):
  add_subdirectory given source ".cppan" which is not an existing directory.


Could NOT find LibArchive (missing: LibArchive_LIBRARY LibArchive_INCLUDE_DIR) 
No support for auto-detection of the target instruction set/extension

General configuration for Tesseract 5.0.0-alpha
--------------------------------------------------------
Build type: 
Compiler: Clang
Used standard: C++14
CXX compiler options:  -isystem E:/Lib_prebuild/android-ndk-r16b/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=14 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security   --std=c++11
Linker options: -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a --sysroot E:/Lib_prebuild/android-ndk-r16b/platforms/android-14/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--gc-sections -Wl,-z,nocopyreloc  
Install directory: E:/Lib_prebuild/tesseract/build_arm7
Architecture flags: 
Vector unit list: 
AVX_OPT: OFF
AVX2_OPT: OFF
SSE41_OPT: OFF
MARCH_NATIVE_OPT: OFF
sim_flags: 

Build with cppan [CPPAN_BUILD]: OFF
Build with openmp support [OPENMP_BUILD]: OFF
Disable disable graphics (ScrollView) [GRAPHICS_DISABLED]: OFF
Enable embedded build [EMBEDDED]: OFF
Disable the legacy OCR engine [DISABLED_LEGACY_ENGINE]: OFF
Build training tools [BUILD_TRAINING_TOOLS]: ON
Build tests [BUILD_TESTS]: OFF
--------------------------------------------------------

Configuring incomplete, errors occurred!
See also "E:/Lib_prebuild/tesseract/prebuild_arm7/CMakeFiles/CMakeOutput.log".
See also "E:/Lib_prebuild/tesseract/prebuild_arm7/CMakeFiles/CMakeError.log".

CMakeError.log

It look like problem is with using OpenCL.

@zdenop
Copy link
Contributor

zdenop commented Jun 7, 2019

@Bleach665 can you please do check once more time?

@Bleach665
Copy link
Author

Bleach665 commented Jun 7, 2019

@zdenop.
Tested on
Winsows 10 x64, CMake gui 3.13.4, MinGW 530_32 (from Qt lib), Android NDK r16b toolchain, rev 17c8ac2.
Tesseract was configured with CMake GUI and Android toolchain and built with MinGW.
Configuration was successful, but build failed.
Build errors:

[ 99%] Built target libtesseract
[100%] Linking CXX executable bin\tesseract
E:/Lib_prebuild/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot find -lpvt.cppan.demo.gif
E:/Lib_prebuild/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot find -lpvt.cppan.demo.jpeg
E:/Lib_prebuild/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot find -lpvt.cppan.demo.png
E:/Lib_prebuild/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot find -lpvt.cppan.demo.tiff
E:/Lib_prebuild/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot find -lpvt.cppan.demo.webmproject.webp
E:/Lib_prebuild/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot find -lpvt.cppan.demo.openjpeg.openjp2
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
CMakeFiles\tesseract.dir\build.make:87: recipe for target 'bin/tesseract' failed
mingw32-make.exe[2]: *** [bin/tesseract] Error 1
CMakeFiles\Makefile2:108: recipe for target 'CMakeFiles/tesseract.dir/all' failed
mingw32-make.exe[1]: *** [CMakeFiles/tesseract.dir/all] Error 2
Makefile:128: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2

CMake changes:

BUILD_TRAINING_TOOLS:BOOL=0
OPENMP_BUILD:BOOL=0
CMAKE_INSTALL_PREFIX:PATH=E:/Lib_prebuild/tesseract/build_arm7
Leptonica_DIR:PATH=E:/Lib_prebuild/leptonica/build_arm7/cmake
CPPAN_BUILD:BOOL=0
TARGET_ARCHITECTURE:STRING=armeabi-v7a
CMAKE_MAKE_PROGRAM:FILEPATH=C:/Lib/Qt/Tools/mingw530_32/bin/mingw32-make.exe

@zdenop
Copy link
Contributor

zdenop commented Jun 7, 2019

Can you please make a clean build (maybe including git cloning).
Because cannot find -lpvt.cppan.demo.tiff indicate you run cppan build...

@Bleach665
Copy link
Author

Build was clean and repo cloned from scratch.

@zdenop
Copy link
Contributor

zdenop commented Jun 7, 2019

than please provide full log from configuration.

@Bleach665
Copy link
Author

Bleach665 commented Jun 7, 2019

Configuring tesseract version 5.0.0-alpha-152-g17c8a...
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) 
Could NOT find LibArchive (missing: LibArchive_LIBRARY LibArchive_INCLUDE_DIR) 
No support for auto-detection of the target instruction set/extension

General configuration for Tesseract 5.0.0-alpha-152-g17c8a
--------------------------------------------------------
Build type: 
Compiler: Clang
Used standard: C++17
CXX compiler options:  -isystem E:/Lib_prebuild/android-ndk-r16b/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=14 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security  
Linker options: -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a --sysroot E:/Lib_prebuild/android-ndk-r16b/platforms/android-14/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--gc-sections -Wl,-z,nocopyreloc  
Install directory: O:/21/tesseract_arm_inst
Architecture flags: 
Vector unit list: 
AVX_OPT: OFF
AVX2_OPT: OFF
SSE41_OPT: OFF
MARCH_NATIVE_OPT: OFF
sim_flags: 

Build with cppan [CPPAN_BUILD]: OFF
Build with openmp support [OPENMP_BUILD]: OFF
Disable disable graphics (ScrollView) [GRAPHICS_DISABLED]: OFF
Enable embedded build [EMBEDDED]: OFF
Disable the legacy OCR engine [DISABLED_LEGACY_ENGINE]: OFF
Build training tools [BUILD_TRAINING_TOOLS]: OFF
Build tests [BUILD_TESTS]: OFF
--------------------------------------------------------

Configuring done
Generating done

UPD. Sorry, I forgot about log files. I looked at them - there's a couple of mistakes.
CMakeFiles.zip

@zdenop
Copy link
Contributor

zdenop commented Jun 9, 2019

  1. I downloaded the latest ndk (r20) and it provide make tool \android-ndk-r20\prebuilt\windows-x86_64\bin\make.exe ), so there is not need to use Qt mingw make file. IMO it is better to use tools from one source instead of multiple sources/providers.
  2. Your output is reconfigure output from cmake-gui! Full/clean configure seems like this:
ANDROID_PLATFORM not set. Defaulting to minimum supported version
16.
Check for working C compiler: F:/0Android/android-ndk-r20/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
Check for working C compiler: F:/0Android/android-ndk-r20/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: F:/0Android/android-ndk-r20/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe
Check for working CXX compiler: F:/0Android/android-ndk-r20/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done

And I guess problem is that you first (clean) run is started as cppan build and then you try to reconfigure at non cppan build, but is does not work (cmake uses cached results during reconfiguration!)
So you either remove .cppan dir (and probably cppan tool from path) or you correcting initialize cmake variables before running initial cmake configuration:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants