I am trying to call a .so file from zig; (on Linux; I would also like it to be able to work on Windows)
This is the file I am compiling to a .so (zig build-lib math.zig) (I then rename the output to liba.so)
Other info :
Arch Linux
Zig 0.15.1
math.zig:
export fn add(x : f32, y : f32) callconv(.c) f32 {
return x + y;
}
main.zig :
const std = @import("std");
const print = std.debug.print;
pub fn main() !void {
var dynLib = try std.DynLib.open("./liba.so");
defer dynLib.close();
const math_fn = dynLib.lookup(*const fn (f32, f32) callconv(.c) f32, "add").?;
const r = math_fn(10.0, 5.0);
print("Res : {d:.3}\n", .{r});
}
Error :
error: NotElfFile
*(my_path)*/lib/std/dynamic_library.zig:245:56: 0x113fcb9 in open (std.zig)
if (!mem.eql(u8, eh.e_indent[0..4], elf.MAGIC)) return error.NotElfFile;
*(my_path)*/lib/std/dynamic_library.zig:32:28: 0x113e016 in open (std.zig)
return .{ .inner = try InnerType.open(path) };
*(my_path)*/dyn/ex.zig:5:18: 0x113c780 in main (ex.zig)
var dynLib = try std.DynLib.open("./liba.so");