vosk-api icon indicating copy to clipboard operation
vosk-api copied to clipboard

Go Binding statically references resources outside of the go module's scope

Open ajohnson-veri opened this issue 2 years ago • 7 comments

Issue

I'm working an a golang application that will is trying to use Vosk offline and saw the new go bindings. When I attempted to use the binding I get the following error...

ld: warning: directory not found for option '-L/Users/myUser/go/pkg/mod/github.com/alphacep/vosk-api/[email protected]/../src'

The issue here is that when you install a go module it considers the directory with the go.mod file in it as the parent directory and installs from that point down (sub-dirs - no parents). This means that installing only the go module won't compile because it won't have access to the src parent directory where the C header files are located.

A similar use case in another application I work is to build the binding with the following settings...

/*
#cgo CXXFLAGS: -std=c++11
#cgo LDFLAGS: -lmyLibName
#include "my_header_file.h"
#include "stdlib.h"
*/
import ....

And then I include my own settings for the -I and -L CGO flags at build time. (Setting this options regardless did not override the ones in the binding)

CGO_LDFLAGS="-L/tmp/myLibName/lib/"
CGO_CXXFLAGS="-I/tmp/myLibName/include/"

This allows consumers to configure their artifacts/resources as needed and makes integrating with go modules much easier.

If there is simply a step I've missed in getting the go binding properly installed let me know, otherwise adjusting the CGO settings would be appreciated. Thanks!

Ref: https://github.com/alphacep/vosk-api/blob/master/go/vosk.go#L3

ajohnson-veri avatar Sep 29 '21 00:09 ajohnson-veri

Yeah, it is a problem with go and a good idea to document it better to download binary build from release and install it properly.

Overall go design is awful here.

If you could submit a basic readme on this, it would be deeply appreciated.

nshmyrev avatar Sep 29 '21 23:09 nshmyrev

A solution would be to embed the libraries and extract them like in Porcupine:

https://github.com/Picovoice/porcupine/blob/master/binding/go/porcupine.go#L143

nshmyrev avatar Nov 06 '21 15:11 nshmyrev

I downloaded vosk-win64-0.3.42.zip but did not get it at what folder/path shall I unpack it

hajsf avatar Jun 25 '22 13:06 hajsf

I believe it has to be ../src. Try to compile and see how it complains. It will tell you where the library is needed.

nshmyrev avatar Jun 25 '22 13:06 nshmyrev

I believe it has to be ../src

I got the below error:

# github.com/alphacep/vosk-api/go
D:\Development\gopath\pkg\mod\github.com\alphacep\vosk-api\[email protected]\vosk.go:6:11: fatal error: vosk_api.h: No such file or directory
    6 | // #include <vosk_api.h>
      |           ^~~~~~~~~~~~
compilation terminated.

I copied the extracted files at: D:\Development\gopath\pkg\mod\github.com\alphacep\vosk-api\[email protected] and at: D:\Development\gopath\pkg\mod\github.com\alphacep\[email protected]\src

Then tried to run the code, but this time got:

PS D:\Deployment\vosk> go run stt
# github.com/alphacep/vosk-api/go
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lvosk
D:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ldl
collect2.exe: error: ld returned 1 exit status

Note: I'm running my code at Windows 10 x64 machine

The files I copied are: image

hajsf avatar Jun 25 '22 14:06 hajsf

Same.. is there any solution for this

poovarasanvasudevan avatar Jul 05 '22 13:07 poovarasanvasudevan

is there any solution for this

The issue is tracked at #672

hajsf avatar Jul 05 '22 15:07 hajsf