Calling tdlib-json from zig segfaults?

I’m trying to call tdlib-json from zig

Version: 0.12.0-dev.3653+e45bdc6bd

const td = @cImport({
@cInclude("td/telegram/td_json_client.h");                        
});                                                                                                                                                                                   pub fn main() void{                                                      
 _ = td.td_json_client_create();
}

Compiled with

zig build-exe telez.zig -I tdlib/include -L tdlib/lib -ltdjson

And the crash is
Segmentation fault at address 0x0
???:?:?: 0x0 in ??? (???)

I think you need to link libc via -lc

zig build-exe telez.zig -lc -I tdlib/include -L tdlib/lib -ltdjson
1 Like
On ldd telez(the executable) libtdjson.so.1.8.27 => /data/data/com.termux/files/home/tdlib/lib/libtdjson.so.1.8.27 libssl.so.3 => /data/data/com.termux/files/usr/lib/libssl.so.3 libcrypto.so.3 => /data/data/com.termux/files/usr/lib/libcrypto.so.3 libdl.so => /system/lib64/libdl.so libz.so.1 => /data/data/com.termux/files/usr/lib/libz.so.1 liblog.so => /system/lib64/liblog.so libc++_shared.so => /data/data/com.termux/files/usr/lib/libc++_shared.so libm.so => /system/lib64/libm.so libc.so => /system/lib64/libc.so ld-android.so => /system/lib64/ld-android.so libc++.so => /system/lib64/libc++.so

And on further investigation, this only fails in Android (Termux) but compiles in a linux machine.