|
Oktatás * Programozás 1 * Szkriptnyelvek Teaching * Programming 1 (BI) Félévek Linkek * kalendárium |
Nim2 /
Compilation 🤖The Nim compiler doesn't produce an executable binary directly. Instead, first it compiles to C, and then this C code is compiled with the platform's C compiler (under Linux it's typically the GCC, but you can also use Clang, or some other C compiler). Nim also supports other targets: C++, JavaScript. However, most often we'll use the C backend. The intermediate C code is hidden, and the invokation of the C compiler is also hidden by the Nim compiler. You don't have to deal with the C code, it's managed in the background by the Nim compiler. You'll only see this: $ nim c prg.nim 𝥶Compiles the program in debug mode. Faster compilation, slower EXE. $ nim c -d:release prg.nim 𝥶Compiles the program in release mode. Slower compilation, fast EXE. The EXE is smaller. Silent compilation 🫢By default, the nim compiler gives some feedback about what it's doing. If you don't need this info, you can switch it off: $ nim c --hints:off --warnings:off prg.nim Create a fast EXE ⚡Here is how you can optimize for speed: $ nim c -d:release --opt:speed prg.nim On Linux, there's a high chance that the default C compiler is GCC. Sometimes, Clang produces faster EXEs. You can also try that: $ nim c --cc:clang -d:release prg.nim $ nim c --cc:clang -d:release --opt:speed prg.nim Create a small EXE 🤏I took the same program and compiled it with different options. File sizes are indicated. $ nim c prg.nim # 98336 bytes $ nim c -d:release prg.nim # 69288 bytes $ nim c -d:release --opt:size prg.nim # 38168 bytes $ nim c -d:release --opt:size --passL:-s prg.nim # 27120 bytes $ nim c -d:release --opt:size -d:quick --passL:-s prg.nim # 26912 bytes " Applying UPX 📦If you want to further minimize the size of the binary, you can also experiment with upx. Take the smallest binary and try these: $ upx <binary> # fast; good compression $ upx --best <binary> # better compression $ upx --lzma <binary> # even better than "--best" :) After UPX, always try the EXE to check if it still works. Links 🔗 |
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |