Recent Changes - Search:

Oktatás

* Programozás 1
  + feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

Teaching

* Programming 1 (BI)
  ◇ exercises
  ◇ quick link

teaching assets


Félévek

* 2025/26/2
* archívum


Linkek

* kalendárium
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C#
* D lang.
* Java
* Nim
* Nim2
  + exercises
* XC=BASIC
* old
  ◇C++, ◇Clojure, ◇Scala


[ edit | logout ]
[ sandbox | passwd ]

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 source code][Nim compiler][runnable EXE]

$ 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

"--passL:-s" calls "strip -s"

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 🔗

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2026 April 08, 22:05