Zum Hauptinhalt springen
•
YouTube Security VideosMicrosoft Developer: Migrate to Azure SQL. Then Build Something New(20.10.2026 um 23:00 Uhr)
••
YouTube Security VideosMicrosoft Developer: SQL Server 2025: AI-Ready Wherever You Run It(20.10.2026 um 23:00 Uhr)
•••
YouTube Security VideosMicrosoft Developer: Hyperscale for Every Workload(20.10.2026 um 23:00 Uhr)
•
YouTube Security VideosMicrosoft Developer: SQL Meets Fabric: Migrate, Mirror, Build(20.10.2026 um 23:00 Uhr)
••••
YouTube Security VideosMicrosoft Developer: Migrate to Azure SQL. Then Build Something New(20.10.2026 um 23:00 Uhr)
••
YouTube Security VideosMicrosoft Developer: SQL Server 2025: AI-Ready Wherever You Run It(20.10.2026 um 23:00 Uhr)
•••
YouTube Security VideosMicrosoft Developer: Hyperscale for Every Workload(20.10.2026 um 23:00 Uhr)
•
YouTube Security VideosMicrosoft Developer: SQL Meets Fabric: Migrate, Mirror, Build(20.10.2026 um 23:00 Uhr)
•••
Intelligence View
⚡ tsecurity.de Intelligence

You have been zigged (series) : Linking static library

Blog no. 05 In this blog, we will explore how to link a zig library statically and dynamically. First lets create a library that contains a function my_add…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!

Blog no. 05

In this blog, we will explore how to link a zig library statically and dynamically.



First lets create a library that contains a function my_add that adds two numbers. Note that instead of pub keyword which we used in previous blog, we will be using export keyword to decorate the my_add function.




// libraries__add.zig
export fn my_add(num1: i32, num2: i32) i32 {
return num1 + num2;
}






Build the libraries__add.zig file as a static library using the command zig build-lib -O ReleaseSafe libraries__add.zig. This will output a liblibraries__add.a file on current folder.



To use this my_add function in our main code to add numbers, we will declare the my_add function's signature in main code using extern keyword. Then at compile time, we will tell the zig compiler to link the liblibraries__add.a with our main output.




// libraries__main1.zig
const std = @import("std");

extern fn my_add(num1: i32, num2: i32) i32;

pub fn main(init: std.process.Init) !void {
// setting up stdout writer
var buffer: [1024]u8 = undefined;
var file_writer = std.Io.File.Writer.init(.stdout(), init.io, &buffer);
var stdout_writer = &file_writer.interface;

try stdout_writer.print("{}+{}={}\n", .{ 5, 6, my_add(5, 6) });
try stdout_writer.flush();
}






Let's build our main code and link liblibraries__add.a with the output using zig build-exe libraries__main1.zig liblibraries__add.a.



The above command will produce a libraries__main1 which when executed will print 5+6=11.



Thanks for reading. To be continued.

🔍 CTI & Forensik

Cyber Threat Intelligence & Forensik

ATT&CK-Navigator · IoC-Radar · Exploit-Belege
CTI Threat Relationship Graph
Akteure · Techniken · Beziehungen
2 Knoten · 1 Relationen
CVE / Incident Threat Actor Software MITRE ATT&CK CWE Weakness IoC
Intelligence Digest — free The top security news daily · unsubscribe anytime
Community Rating & Social Proof
⭐ Leser-Wertung
–
Ø / 5.0
No reader ratings yet
Was this page helpful?
0
Jetzt Bewertung abgeben
🟢 Niedrig (1-3.9) 🟡 Mittel (4.0-6.9) 🔴 Hoch (7.0-8.9) Kritisch (9.0-10.0)
Similar posts
🔍 Verwandte News

Auch interessante Nachrichten You have been zigged (series) : Linking static library

Thematisch verwandte Begriffe: have, been, zigged, series · 6 Treffer

Laden...

Loading videos ...

Laden...

Loading posts ...

Laden...

Loading videos ...

Laden...

Loading posts ...

Laden...

Loading videos ...

Laden...

Loading posts ...

Laden...

Loading videos ...

Laden...

Loading posts ...

Laden...

Loading videos ...

💬 Loading comments…
Pull to refresh
Nächster Beitrag