ターゲットと-targetトリプル
OS、アーキテクチャ、ABIを指定します
「ターゲットと-targetトリプル」はCoddyKit上の無料Zig Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはZig Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Zig Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Cross-Compiling Is Built In
Zig ships every supported target inside the compiler, so cross-compilation needs no extra toolchains or downloads to begin.
The Target Triple
You name a target with a triple: it spells out the CPU architecture, the operating system, and the ABI in one string.
x86_64-linux-gnuThree Parts, One String
Read a triple left to right as arch-os-abi. Each part narrows down exactly which binary the compiler should produce.
aarch64-macos-nonePass It with -target
You select a target on the command line with the -target flag, and Zig builds for that machine instead of your own.
zig build-exe main.zig -target aarch64-linux-muslThe Architecture Part
The first field is the architecture, like x86_64, aarch64, or riscv64. It decides the instruction set of the output.
The OS Part
The middle field is the operating system, such as linux, macos, or windows. It shapes system calls and file formats.
The ABI Part
The last field is the ABI, like gnu, musl, or msvc. It picks the C library and calling conventions to match.
List Every Target
Not sure which triples exist? Ask Zig to print them all. zig targets dumps the supported architectures, OSes, and ABIs.
zig targetsYour Native Target
With no -target flag, Zig builds for the native triple: the same arch, OS, and ABI as the machine you are on.
Omitting Parts
You can leave fields off and Zig fills in a sensible default. x86_64-linux works because the ABI is chosen for you.
zig build-exe main.zig -target x86_64-linuxTune the CPU Model
You can refine the architecture with a CPU model after a plus sign, asking Zig to use features of a specific processor.
zig build-exe main.zig -target x86_64-linux -mcpu=baselineQuick Check
Recall the order of fields inside a target triple.
Recap
You learned that a target triple names arch, OS, and ABI, and that -target lets Zig build for any of them. 🌍
よくある質問
「ターゲットと-targetトリプル」レッスンは無料ですか?
はい。「ターゲットと-targetトリプル」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Zig Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Zig Academyコースには全4レッスンが含まれています。
「ターゲットと-targetトリプル」で何を学びますか?
OS、アーキテクチャ、ABIを指定します ブラウザで直接実行するハンズオンコードでZig Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Zig Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのZig Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「ターゲットと-targetトリプル」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このZig Academyレッスンでコードを書いて実行できますか?
はい。すべてのZig Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- ターゲットと-targetトリプル
- Linux、macOS、Windows向けのビルド
- zig ccによるCのクロスコンパイル
- 静的バイナリとmusl