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

2024-04-03 Β· 313 words

Zig + Nvim μ„€μ •

last updated: {{ β€œ1710903265” | date: β€œ%Y-%m-%d %H:%M” }} Intro neovimμ—μ„œ zig μ„€μ • 방법을 μ„€λͺ…ν•œλ‹€. Install on Alpine μ„€μΉ˜ν•˜κΈ° $ doas apk add zig zls neovim $ nvim ~/.local/nvim/init.lua require 'lspconfig'.zls.setup{} λ‹€λ₯Έ μ–΄λ–€ 언어보닀도 섀정이 κ°„λ‹¨ν•˜λ‹€. zlsλŠ” zig language server lspconfigλŠ” neovim에 λ‚΄μž₯된 LSP 섀정을 λ§ν•œλ‹€. nvim μ„€μ • ν›„ zigνŒŒμΌμ„ μ—΄κ³  μ½”λ”©ν•˜λ©΄ 도움말이 λ‚˜νƒ€λ‚œλ‹€. tab으둜 μ΄λ™ν•˜κ³  Enter둜 μ„ νƒν•œλ‹€. Install zls from Source μ†ŒμŠ€λ₯Ό μ»΄νŒŒμΌν•˜λŠ” 방법. μ΅œμ‹  λ²„μ „μ˜ zig(ν˜„μž¬ 0.12)이어야 git μ†ŒμŠ€λ‘œ 컴파일 λœλ‹€. zig μ΅œμ‹  버전은 zig ν™ˆμ—μ„œ λ‹€μš΄λ‘œλ“œν•  수 μžˆλ‹€. λ‹€μŒ μ ˆμ°¨μ— 따라 λΉŒλ“œν•œλ‹€. $ git clone https://github.com/zigtools/zls $ cd zls $ zig build -Doptimize=ReleaseSafe $ mkdir ~/bin && cp zig-out/bin/zls ~/bin $ echo 'export PATH=$HOME/bin:$PATH' >> ~/.bash_profile $ source ~/.bash_profile $ zls --version Links Neovim setup for Zig https://terminalprogrammer.com/neovim-setup-for-zig

2024-03-12 Β· 121 words