Zigλ‘ gcc/clang μ»΄νμΌλ¬ λ체νκΈ°
last updated: {{ β1712680347β | date: β%Y-%m-%d %H:%Mβ }} Intro zigλ‘ c μμ€λ₯Ό μ»΄νμΌν μ μλ€. zigμ μ₯μ μ μ¬λ¬ νλ«νΌκ³Ό μν€ν μ²μ© μ»΄νμΌμ΄ κ°λ₯νλ€λ κ²μ΄λ€. static, dynamic λͺ¨λ κ°λ₯νλ€. Linux, iOS, Windows λ± μ¬λ¬ OS νκ²½ μ§μ. x86, , x86-64, aarch64 λ± μν€ν μ² μ§μ Target List λ€μ λ°©λ²μΌλ‘ μνλ νλ«νΌ, μν€ν μ³λ₯Ό λ¨Όμ μ°Ύλλ€. $ zig targets $ zig targets | grep x86 $ zig targets | grep x86-64 $ zig targets | grep aarch64 $ zig targets | grep linux $ zig targets | grep windows $ zig targets | grep macos x86, x86_64 - intel κ³μ΄ aarch64 - arm κ³μ΄ (raspberrypi) linux - Linux windows - Ms Windows macos - Mac OS Local Compile dynamic: Alpine Linux (x86_64) $ zig cc -o hello_dynamic hello.c $ file hello_dynamic hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, with debug_info, not stripped $ ./hello Hello World! static: Alpine Linux (x86_64) $ zig cc -o hello hello.c -target x86_64-linux-musl $ file hello ./hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped $ ./hello Hello World! Cross Compile For windows $ zig cc -o hello.exe hello.c -target x86_64-windows-gnu $ file ./hello.exe hello: PE32+ executable (console) x86-64, for MS Windows, 7 sections Windows c:> .\hello.exe Hello World! For Linux dynamic with Gnu Libs $ zig cc -o hello hello.c -target x86_64-linux-gnu $ file ./hello.exe ./hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.0.0, with debug_info, not stripped gnu-linux$ ./hello Hello World! For Linux Static with musl $ zig cc -o hello.exe hello.c -target x86_64-linux-gnu $ file ./hello.exe ./hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped any-linux$ ./hello Hello World! Makefile or Build.sh ν΄λΉ νμΌμμ gcc, clang λΆλΆμ zig ccλ‘ μμ νλ€. make λλ ./Build.sh μ€ν Links zig cc: a Powerful Drop-In Replacement for GCC/Clang https://andrewkelley.me/post/zig-cc-powerful-drop-in-replacement-gcc-clang.html