Building go binding inside Termux (Android ARM)

48 views
Skip to first unread message

Ronoaldo Pereira

unread,
Oct 15, 2020, 11:33:05 AM10/15/20
to tesseract-ocr
Hi!

I am trying to build a small utility using tesseract from a Go program, and instead of calling a subprocess and initializing the OCR engine every time I plan to run the OCR from a Go routine.

I have this small code that uses a binding to tesseract:

$ cat main.go 
package main

import (
        "io/ioutil"
        "os"
        "fmt"
        "log"

)

func main() {
        client := gosseract.NewClient()
        defer client.Close()

        b, err := ioutil.ReadAll(os.Stdin)
        if err != nil {
                log.Fatal("Error loading image from stdin: %v", err)
        }
        if err := client.SetImagesFromBytes(b); err != nil {
                log.Fatal("Invalid image format from stdin: %v", err)
        }
        hocr, err := client.HOCR()
        if err != nil {
                log.Fatal("Error performing hOCR: %v", err)
        }
        fmt.Println(hocr)
}

When I try to compile using the version 4.1.1 of tesseract (from pkg install tesseract inside Termux) I get this errors:

/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: /data/data/com.termux/files/usr/lib/libtesseract.so: undefined reference to `omp_get_thread_num'
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: /data/data/com.termux/files/usr/lib/libtesseract.so: undefined reference to `__kmpc_serialized_parallel'
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: /data/data/com.termux/files/usr/lib/libtesseract.so: undefined reference to `__kmpc_push_num_threads'
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: /data/data/com.termux/files/usr/lib/libtesseract.so: undefined reference to `__kmpc_for_static_init_4'
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: /data/data/com.termux/files/usr/lib/libtesseract.so: undefined reference to `__kmpc_end_serialized_parallel'
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: /data/data/com.termux/files/usr/lib/libtesseract.so: undefined reference to `__kmpc_global_thread_num'
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: /data/data/com.termux/files/usr/lib/libtesseract.so: undefined reference to `__kmpc_fork_call'
/data/data/com.termux/files/usr/bin/arm-linux-androideabi-ld: /data/data/com.termux/files/usr/lib/libtesseract.so: undefined reference to `__kmpc_for_static_fini'
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)

I don't know if this issue is in my code, the lib binding or the Termux build of tesseract. Any help to dissect this will be apreciated!

Best regards,

Ronoaldo Pereira

unread,
Oct 15, 2020, 12:24:38 PM10/15/20
to tesseract-ocr
When testing the code on PC there were errors in the Go code, but they are unrelated to the build errors from libtesseract.so:

```
package main

import (
       "io/ioutil"
       "os"
       "fmt"
       "log"

       "github.com/otiai10/gosseract"
)

func main() {
       client := gosseract.NewClient()
       defer client.Close()

       b, err := ioutil.ReadAll(os.Stdin)
       if err != nil {
               log.Fatal("Error loading image from stdin: %v", err)
       }
       if err := client.SetImageFromBytes(b); err != nil {
               log.Fatal("Invalid image format from stdin: %v", err)
       }
       hocr, err := client.HOCRText()
       if err != nil {
               log.Fatal("Error performing hOCR: %v", err)
       }
       fmt.Println(hocr)
}
```
Since I could build and run this program on my PC with no errors, it seems to be related to the build toolchain on android. Apologise for the confusion here! I filled a bug report on termux-packages repository: https://github.com/termux/termux-packages/issues/5946

Best Regards,
Reply all
Reply to author
Forward
0 new messages