C binding for struct array?

53 views
Skip to first unread message

Lev Khusid

unread,
Nov 22, 2018, 8:11:36 AM11/22/18
to Crystal
I am trying to get C function binding that returns an array of structs.   Specific example would be in ReadLine lib - function "history_list":


I tried to do this:

lib LibReadline
struct HistoryEntry
line : UInt8*
# timestamp : UInt8*
# data : Void*
end
alias HistEntryArray = HistoryEntry*

fun write_history(file : UInt8*) : Int32
fun read_history(file : UInt8*) : Int32
fun stifle_history(Int32)
fun history_get(Int32) : HistoryEntry*
fun history_list() : HistEntryArray*
end


All function bindings work except "history_list".   If I call it in the code like this:

y = LibReadline.history_list()

I get:

Undefined symbols for architecture x86_64:

  "_history_list", referenced from:

      ...

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Error: execution of command failed with code: 1: `cc "${@}" -o '/Users/lkhusid/.cache/crystal/crystal-run-tekton-cli.tmp'  -rdynamic  -lreadline -lz `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto'` -lpcre -lgc -lpthread /usr/local/Cellar/crystal/0.27.0/src/ext/libcrystal.a -levent -liconv -ldl -L/usr/lib -L/usr/local/lib`



What am I doing wrong?

Reply all
Reply to author
Forward
0 new messages