2

I'm using gosseract, a Go OCR package that uses Tesseract for reading characters from images. I am using the demo's code right now like so:

client := gosseract.NewClient()
defer client.Close()
client.SetImage("helloworld.png")
text, _ := client.Text()
fmt.Println(text)

That's fine, but when I run the program it prints out:

# github.com/otiai10/gosseract
tessbridge.cpp: In function ‘int Init(TessBaseAPI, char*, char*, char*, char*)’:
tessbridge.cpp:46:10: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   46 |   freopen("/dev/null", "a", stderr);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
tessbridge.cpp:60:10: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |   freopen("/dev/null", "a", stderr);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Hello World!

The warnings print regardless of whether I output text or not

Is there any way I can just suppress the warnings at the beginning of my output? I know this problem is probably better suited for the Issues section of that package, but I wanted to know if there was a built in way to hide those messages in any package.

kostix
  • 51,517
  • 14
  • 93
  • 176
  • 5
    The go compiler does not emit warnings, those are coming from gcc – JimB Aug 02 '21 at 18:53
  • Maybe setting env var `CGO_CFLAGS` to `-w` would work? – Zyl Aug 02 '21 at 19:08
  • 1
    Please consider reopening [this issue](https://github.com/otiai10/gosseract/issues/214) and commenting that not checking the result of `freopen` is a bug—even in such a trivial case (I hardly imagine a working Unix-like system able to run tesseract which does not have a usable `/dev/null` special file). The fix is trivial; for instance, you can point the upstream devs [there](https://www.mail-archive.com/bug-wget@gnu.org/msg09763.html). – kostix Aug 02 '21 at 19:14
  • @JimB So what's the best course of action then? – user16580216 Aug 02 '21 at 19:23
  • @user16580216, fix the code in `tessbridge.cpp` to suppress the warnings or do what @Zyl said. Also please do not dismiss my own advice: the problem with gosseract is very real. – kostix Aug 03 '21 at 10:23

0 Answers0