0Pricing
Zig Academy · レッスン

実行ファイルとライブラリを宣言する

ビルドグラフにアーティファクトを追加します。

「実行ファイルとライブラリを宣言する」はCoddyKit上の無料Zig Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはZig Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Zig Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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. 🎯

よくある質問

「実行ファイルとライブラリを宣言する」レッスンは無料ですか?

はい。「実行ファイルとライブラリを宣言する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Zig Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Zig Academyコースには全4レッスンが含まれています。

「実行ファイルとライブラリを宣言する」で何を学びますか?

ビルドグラフにアーティファクトを追加します。 ブラウザで直接実行するハンズオンコードでZig Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Zig Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのZig Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「実行ファイルとライブラリを宣言する」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このZig Academyレッスンでコードを書いて実行できますか?

はい。すべてのZig Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. build.zigファイルの構造
  2. 実行ファイルとライブラリを宣言する
  3. ビルドステップとzig build run
  4. ビルドオプションとフラグ
← Zig Academyに戻る