I have installed tesseract 5.3.4
and leptonica 1.84.1
from homebrew
.
When I'm trying to run even the simplest code:
package main
import (
"github.com/otiai10/gosseract"
)
func main() {
client := gosseract.NewClient()
_ = client
}
I get the following error:
/opt/homebrew/Cellar/go/1.22.1/libexec/pkg/tool/darwin_arm64/link:
running c++ failed: exit status 1
ld: warning: ignoring duplicate libraries: '-llept', '-ltesseract'
ld: library 'lept' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've searched through all cmake
files related to tesseract
and leptonica
and couldn't find linker options like -llept
.
Also leptonica
brings shared libraries like libleptonica.6.dylib
not liblept.6.dylib
, but even making corresponding symlinks doesn't help.
Is there any something else I'm missing which is required to make gosseract
work on masOS Sonoma
with go1.22
?
Changing the github.com/otiai10/gosseract/client.go
from:
// #if __FreeBSD__ >= 10
// #cgo LDFLAGS: -L/usr/local/lib -llept -ltesseract
// #else
// #cgo CXXFLAGS: -std=c++0x
// #cgo LDFLAGS: -llept
// #endif
// #include <stdlib.h>
// #include <stdbool.h>
// #include "tessbridge.h"
to:
// #if __FreeBSD__ >= 10
// #cgo LDFLAGS: -L/usr/local/lib -lleptonica -ltesseract
// #else
// #cgo CXXFLAGS: -std=c++0x
// #cgo LDFLAGS: -lleptonica
// #endif
// #include <stdlib.h>
// #include <stdbool.h>
// #include "tessbridge.h"
Did the trick. The problem here is if you choose to do so as well, you'll have to vendor this module in your application and support your version yourself.
As I mentioned in my question, I installed tesseract
and leptonica
using homebrew
. It doesn't touch anything in /usr/local
.
I made a symlink /usr/local/lib -> /opt/homebrew/lib
in order not to edit gosseract
itself further, so this may be not a very good solution.
UPDATE:
In github.com/otiai10/gosseract/v2
(latest version as of 2024-03-06 is 2.4.1) has the -llept
issue sort of fixed, however it is still necessary to synmlink /usr/local/lib
to /opt/homebrew/lib