[SOLVED] Is crystal_lib binding generator broken?

Hi

I just tried to make bindings for libgpiod and thought I’d try the crystal_lib binding generator, but I can’t get it to work.
So, I tried some of the examples, and all of them look like this:

 crystal src/main.cr -- examples/lib_ssl.cr 
Unhandled exception: can't find function SSL_load_error_strings (Exception)
  from src/crystal_lib/lib_body_transformer.cr:17:5 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:7:14 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:23:9 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:7:14 in 'transform'
  from src/crystal_lib/lib_transformer.cr:21:19 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:7:14 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:23:9 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:7:14 in 'transform'
  from src/main.cr:5:1 in '__crystal_main'
  from /usr/share/crystal/src/crystal/main.cr:106:5 in 'main_user_code'
  from /usr/share/crystal/src/crystal/main.cr:92:7 in 'main'
  from /usr/share/crystal/src/crystal/main.cr:115:3 in 'main'
  from __libc_start_main
  from _start
  from ???
crystal src/main.cr -- examples/libc.cr 
Unhandled exception: can't find constant TCP_KEEPALIVE (Exception)
  from src/crystal_lib/lib_body_transformer.cr:38:5 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:7:14 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:23:9 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:7:14 in 'transform'
  from src/crystal_lib/lib_transformer.cr:21:19 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:7:14 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:23:9 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:7:14 in 'transform'
  from src/main.cr:5:1 in '__crystal_main'
  from /usr/share/crystal/src/crystal/main.cr:106:5 in 'main_user_code'
  from /usr/share/crystal/src/crystal/main.cr:92:7 in 'main'
  from /usr/share/crystal/src/crystal/main.cr:115:3 in 'main'
  from __libc_start_main
  from _start
  from ???
crystal src/main.cr -- examples/lib_curses.cr 
Unhandled exception: can't find function refresh (Exception)
  from src/crystal_lib/lib_body_transformer.cr:17:5 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:7:14 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:23:9 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:7:14 in 'transform'
  from src/crystal_lib/lib_transformer.cr:21:19 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:7:14 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:23:9 in 'transform'
  from /usr/share/crystal/src/compiler/crystal/syntax/transformer.cr:7:14 in 'transform'
  from src/main.cr:5:1 in '__crystal_main'
  from /usr/share/crystal/src/crystal/main.cr:106:5 in 'main_user_code'
  from /usr/share/crystal/src/crystal/main.cr:92:7 in 'main'
  from /usr/share/crystal/src/crystal/main.cr:115:3 in 'main'
  from __libc_start_main
  from _start
  from ???

I assume that I’m doing something wrong, but this is supposed to work like that? Right?

Turns out its 2 different things:

  1. there is a pending pull request to crystal_lib which makes most examples work again: https://github.com/crystal-lang/crystal_lib/pull/65
    Or rather I should say fork, because I tried the branch this PR is in and most examples worked again.
  2. I had this:
  @[Include("/usr/include/gpiod.h")]
  @[Link("gpiod")]
  lib LibGpiod
  end

and had to change it to this to work:

@[Include("gpiod.h",
  prefix: %w(gpiod_ GPIOD_),
  import_docstrings: "full")]
@[Link("gpiod")]
lib LibGpiod
end

I assume its the prefix setting. If anyone wants to update the readme with some words about the meaning/usage of prefix, that would be great.
Or just a short reply here and I’ll put it in the readme.