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