2018-06-16 22:01:23 +01:00
|
|
|
const std = @import("std");
|
|
|
|
|
|
|
|
pub fn main() !void {
|
2022-05-26 10:49:05 +01:00
|
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
|
|
defer _ = gpa.deinit();
|
|
|
|
const args = try std.process.argsAlloc(gpa.allocator());
|
|
|
|
defer std.process.argsFree(gpa.allocator(), args);
|
2018-06-16 22:01:23 +01:00
|
|
|
|
|
|
|
const dynlib_name = args[1];
|
|
|
|
|
2019-05-30 04:45:28 +01:00
|
|
|
var lib = try std.DynLib.open(dynlib_name);
|
2018-06-16 22:01:23 +01:00
|
|
|
defer lib.close();
|
|
|
|
|
2023-03-08 07:16:16 +00:00
|
|
|
const Add = *const fn (i32, i32) callconv(.C) i32;
|
2022-07-24 22:05:25 +01:00
|
|
|
const addFn = lib.lookup(Add, "add") orelse return error.SymbolNotFound;
|
2018-06-16 22:01:23 +01:00
|
|
|
|
|
|
|
const result = addFn(12, 34);
|
|
|
|
std.debug.assert(result == 46);
|
|
|
|
}
|