5.3.10 · HinglishBuild Systems & Toolchain

Cross-compilation — toolchains, sysroot

2,104 words10 min readRead in English

5.3.10 · Coding › Build Systems & Toolchain


Cross-compilation exist kyun karta hai?


"Triplet" kya hota hai?


Toolchain kya hota hai?


Sysroot kya hai, aur yeh crux kyun hai?

Figure — Cross-compilation — toolchains, sysroot

HOW: ek poora worked compile


Common mistakes (steel-manned)


Flashcards

Cross-compilation ka kya matlab hai?
Ek machine (host) par ek aisi program build karna jo ek alag machine/architecture (target) par chalti hai.
Compiler vocabulary mein, build/host/target kya hain?
build = jahan compiler build hota hai; host = jahan compiler chalta hai; target = jahan output chalta hai.
Target triplet kya hota hai aur uski shape kya hai?
Ek platform ka naam: <arch>-<vendor>-<os>-<abi/libc>, jaise arm-linux-gnueabihf.
Toolchain kya hota hai?
Tools ka poora matched set (gcc, as, ld, binutils, target libc + headers + startup files) sab ek target triplet ke liye.
Sysroot kya hota hai?
Ek directory tree jo target ke / ki copy karti hai, target headers (usr/include) aur libs (usr/lib) rakhti hai, --sysroot se milti hai.
Host /usr/include ki jagah sysroot kyun zaroori hai?
Host headers/libs host ISA/ABI ke liye hain; unhe link karne se broken binary banti hai. Sysroot target ke headers aur libs supply karta hai.
--sysroot=S search paths ko kaise change karta hai?
Har default root-anchored path p, S+p ban jaati hai (jaise /usr/include → S/usr/include), compiler ke liye ek chroot ki tarah.
aarch64-none-elf mein none ka kya matlab hai?
Koi OS nahi (bare metal); koi libc assumptions nahi — tumhe khud startup aur runtime provide karna hoga.
Autotools ko --host aur --build dono kyun chahiye?
Unki inequality cross build signal karti hai, un run-tests ko disable karti hai jo host par target binaries execute karte.
-ffreestanding kya karta hai?
Compiler ko bolta hai koi hosted runtime/libc nahi hai; main special nahi hai aur standard library functions assumed nahi hain.
gnueabi aur gnueabihf mein antar?
Soft-float vs hard-float ABI; floats integer regs vs FPU regs mein pass hote hain. Inhe mix karna link toh kar deta hai par runtime crash karta hai.
Produce ki gayi binary sahi CPU ke liye hai yeh kaise verify karte hain?
file binary chalao; yeh architecture print karta hai (jaise "ELF 32-bit ARM").

Recall Feynman: 12 saal ke bachche ko samjhao

Socho tum sirf English mein letters likh sakte ho, lekin tumhara dost sirf French padhta hai. Tum use English mein nahi bhejte — pehle translate karte ho. Cross-compiling yahi hai — tumhara computer ek program ko ek bilkul alag computer, jaise ek chote robot, ki "language" (machine code) mein translate karta hai. Lekin sirf words translate karna kaafi nahi: tumhe dost ki dictionary bhi chahiye taaki tum unke words for cheezein use karo. Sysroot woh borrowed dictionary hai — robot ke apne files ki ek copy, taaki tumhara computer program us tarah build kare jaise robot expect karta hai, naki us tarah jaise tumhara computer apne liye karta.

Connections

  • Linkers and the linking process — sysroot badalta hai ki ld symbols kahan resolve karta hai.
  • ELF object file formatfile/objdump woh ELF arch field padhte hain jise tum target kar rahe ho.
  • ABI and calling conventions — soft-float vs hard-float yahan rehta hai.
  • Build systems CMake and autotools--host/toolchain files cross compiler kaise wire in karte hain.
  • Chroot and namespaces — sysroot "compiler ke liye chroot" hai.
  • Static vs dynamic linking — sysroot mein loader ke liye sahi shared libs honi chahiye.

Concept Map

builds for

motivates

separates

separates

names

configures

used as prefix

includes

includes

provides

links against

means

part of

Host machine runs compiler

Target machine runs output

Target too small or bare

Cross-compilation

Target triplet arch-vendor-os-abi

Toolchain

gcc as ld binutils

Sysroot

Target libs and headers

os field none

No libc bare metal