0Pricing
Zig Academy · Урок

Целевые платформы и тройка -target

Указывайте ОС, архитектуру и ABI.

«Целевые платформы и тройка -target» — бесплатный урок Zig Academy на CoddyKit. Это урок 1 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения 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-gnu

Three 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-none

Pass 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-musl

The 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 targets

Your 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-linux

Tune 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=baseline

Quick 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/7) и разблокировать остальной курс Zig Academy, подпишись на CoddyKit PRO. Курс Zig Academy содержит 4 уроков всего.

Чему я научусь в уроке «Целевые платформы и тройка -target»?

Указывайте ОС, архитектуру и ABI. Ты практикуешь Zig Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать Zig Academy?

Предыдущий опыт не требуется. Zig Academy на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 1 из 4.

Сколько времени занимает урок «Целевые платформы и тройка -target»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке Zig Academy?

Да. Каждый урок Zig Academy включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Целевые платформы и тройка -target
  2. Сборка для Linux, macOS и Windows
  3. Кросс-компиляция C с помощью zig cc
  4. Статические бинарные файлы и musl
← Назад к Zig Academy