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

leptonica allheaders.h not found #272

Open
axi92 opened this issue Mar 25, 2023 · 3 comments
Open

leptonica allheaders.h not found #272

axi92 opened this issue Mar 25, 2023 · 3 comments

Comments

@axi92
Copy link

axi92 commented Mar 25, 2023

Summary

  • Installed from here 64bit version https://github.com/UB-Mannheim/tesseract/wiki
  • installed libleponica with cygwin64 (and I can locate all the files, I just dont know where go is searching for the include folder?)
  • and run the example:
package main

import (
	"fmt"

	"github.com/otiai10/gosseract/v2"
)

func main() {
	client := gosseract.NewClient()
	defer client.Close()
	client.SetImage("screens\\tab\\1_1920x1080_20230324121444.png")
	text, _ := client.Text()
	fmt.Println(text)
	// Hello, World!
}

  • and got this error:
# github.com/otiai10/gosseract/v2
tessbridge.cpp:5:10: fatal error: leptonica/allheaders.h: No such file or directory
    5 | #include <leptonica/allheaders.h>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

Things I tried:

  • Add the include folder to the path
  • installed the libs from cygwin
    grafik

Environment

Windows 10
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\User\AppData\Local\go-build
set GOENV=C:\Users\User\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\User\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\User\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=D:\Programme\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\Programme\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.20.2
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\Git\ow-screenshot\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\User\AppData\Local\Temp\go-build2662576145=/tmp/go-build -gno-record-gcc-switches
go version go1.20.2 windows/amd64
tesseract v5.3.0.20221222
 leptonica-1.78.0
  libgif 5.1.4 : libjpeg 8d (libjpeg-turbo 1.5.3) : libpng 1.6.34 : libtiff 4.0.9 : zlib 1.2.11 : libwebp 0.6.1 : libopenjp2 2.3.0
 Found AVX2
 Found AVX
 Found FMA
 Found SSE4.1
 Found libarchive 3.5.0 zlib/1.2.11 liblzma/5.2.3 bz2lib/1.0.6 liblz4/1.7.5 libzstd/1.4.5
 Found libcurl/7.77.0-DEV Schannel zlib/1.2.11 zstd/1.4.5 libidn2/2.0.4 nghttp2/1.31.0

I saw those issues but never found a fix:
#271 #234 #263 #260

@axi92
Copy link
Author

axi92 commented Mar 25, 2023

After I set this:
go env -w CGO_CXXFLAGS="-O2 -g -ID:\Programme\cygwin64\usr\include"
(If somebody is maybe confused whats in the include folder:)
grafik

My error was a different one:

# command-line-arguments
D:\Programme\Go\pkg\tool\windows_amd64\link.exe: running g++ failed: exit status 1
D:/Programme/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -llept
D:/Programme/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ltesseract
D:/Programme/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -llept
D:/Programme/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ltesseract
collect2.exe: error: ld returned 1 exit status

@rockage
Copy link

rockage commented Jun 24, 2023

I spent a lot of time solving this problem. I'm on the Windows platform, but I think it should be similar for other platforms.

First, I installed MSYS2 and used it to install the MinGW toolchain.
Then, I installed Leptonica using pacman. As for Tesseract, I compiled and installed it from source code.
Once I made sure both packages were installed correctly, I used the following command:

pkg-config --cflags --libs lept tesseract

If it shows:
-IC:/msys64/mingw64/include/leptonica -IC:/msys64/mingw64/include -LC:/msys64/mingw64/lib -lleptonica -ltesseract -larchive -lcurl
then everything is fine.

After that, I made modifications to otiai10's code in client.go:

/*
#cgo pkg-config: lept tesseract
#cgo CXXFLAGS: -std=c++0x
#cgo CPPFLAGS: -Wno-unused-result
#include <stdlib.h>
#include <stdbool.h>
#include "tessbridge.h"
*/
import "C"

That solved the problem.

By the way, you also need to set an environment variable TESSDATA_PREFIX to let Tesseract know where your training data is stored.
For example, mine is set to: C:\msys64\usr\local\share\tessdata.

@stevevls
Copy link

I bumped into this same issue on MacOS Ventura 13.5. It seems like that with the latest library versions installed by Homebrew (tesseract@5.3.2, leptonica@1.83.1), one of two things need to happen in order to get this library to work.

  1. Edit this line to read -lleptonica and then set the environment variables as suggested in tessbridge.cpp:5:10: fatal error: leptonica/allheaders.h: No such file or directory #234
  2. Use the pkg-config suggestion above.

The latter doesn't require any environment variables, so it seems a much more portable way to get up and running. I don't fully understand the ramifications of using pkg-config, though. If it doesn't introduce backward incompatibility, would you be open to using it?

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

No branches or pull requests

3 participants