0Pricing
Zig Academy · Lektion

Ausführbare Dateien und Bibliotheken deklarieren

Fügen Sie Artefakte zum Build-Graphen hinzu.

Ausführbare Dateien und Bibliotheken deklarieren ist eine kostenlose Zig Academy-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Zig Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Zig Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Artifacts to Build

The things you compile are called artifacts: an executable you run, or a library other code links against. You declare them in build.zig. 📦

Add an Executable

Create a runnable program with addExecutable. You give it a name and the root source file that holds main.

const exe = b.addExecutable(.{
    .name = "app",
});

Point to the Root Module

The artifact needs a root_module built from your main file, plus the target and optimize values you chose earlier.

.root_module = b.createModule(.{
    .root_source_file = b.path("src/main.zig"),
}),

Carry Target and Optimize

That module also takes the target and optimize fields, so the executable honors whatever the command line requested.

.target = target,
.optimize = optimize,

Install the Output

Creating an exe is not enough; tell Zig to place it in zig-out with installArtifact so the default build emits it.

b.installArtifact(exe);

Where Outputs Land

Installed binaries appear under zig-out/bin by convention. Run zig build and look there for your freshly compiled program.

zig-out/bin/app

Add a Library

For reusable code, use addLibrary instead. It produces a library artifact others can import and link against.

const lib = b.addLibrary(.{
    .name = "mathz",
});

Static or Dynamic

A library can be static (baked into the caller) or dynamic (a shared file). You set linkage when you declare the library.

.linkage = .static,

Link Library into Exe

Connect them so the exe can call the library's code: use linkLibrary to add the dependency edge.

exe.linkLibrary(lib);

Need libc?

If your code calls C standard functions, request libc on the artifact with linkLibC so the right system library is linked.

exe.linkLibC();

A Graph of Artifacts

Each artifact is a node; linking adds edges. Together they form the build graph Zig walks when you run the build. ✅

Quick Check

Recall which call actually emits a built binary into zig-out.

Recap

You declared artifacts with addExecutable and addLibrary, set their root module and target, then used installArtifact and linkLibrary to wire them. 🎯

Häufig gestellte Fragen

Ist die Lektion „Ausführbare Dateien und Bibliotheken deklarieren“ kostenlos?

Ja — der vollständige Text von „Ausführbare Dateien und Bibliotheken deklarieren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Zig Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Zig Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Ausführbare Dateien und Bibliotheken deklarieren“?

Fügen Sie Artefakte zum Build-Graphen hinzu. Du übst Zig Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Zig Academy zu starten?

Keine Vorkenntnisse erforderlich. Zig Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.

Wie lange dauert die Lektion „Ausführbare Dateien und Bibliotheken deklarieren“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Zig Academy-Lektion Code schreiben und ausführen?

Ja. Jede Zig Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Aufbau einer build.zig-Datei
  2. Ausführbare Dateien und Bibliotheken deklarieren
  3. Build-Schritte und zig build run
  4. Build-Optionen und Flags
← Zurück zu Zig Academy