mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 23:52:31 +00:00
20 lines
562 B
Zig
20 lines
562 B
Zig
const std = @import("std");
|
|
|
|
pub fn main() !void {
|
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
defer _ = gpa.deinit();
|
|
const args = try std.process.argsAlloc(gpa.allocator());
|
|
defer std.process.argsFree(gpa.allocator(), args);
|
|
|
|
const dynlib_name = args[1];
|
|
|
|
var lib = try std.DynLib.open(dynlib_name);
|
|
defer lib.close();
|
|
|
|
const Add = *const fn (i32, i32) callconv(.C) i32;
|
|
const addFn = lib.lookup(Add, "add") orelse return error.SymbolNotFound;
|
|
|
|
const result = addFn(12, 34);
|
|
std.debug.assert(result == 46);
|
|
}
|