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 ]

Compiling a Nim program with zig

Install the "zigcc" Nim package that wraps `zig cc` to be able to be called by the Nim compiler:

$ nimble install zigcc

Now you get a command "zigcc" (no space) that will call "zig cc" (space) for you. Check if it works:

$ zigcc main.c

$ ./a.out
hello

This requires the presence of the zig compiler. That is, first you must install zig on your computer.

Why should you use it under Windows?

As we know, the Nim compiler produces a C code that is further compiled with a C compiler. If you use MinGW under Windows, then you'll have problems with the EXEs. There's nothing wrong with the EXE but your antivirus software will always complain that the EXE is suspicious. Why? Not many people use MinGW under Windows, thus the EXEs created by a MinGW C compiler is suspicious for your antivirus software :(

However, if you tell Nim to use `zig cc`, the produced EXEs will be accepted by the antivirus softwares. You'll get less false alarms.

Let's see how to compile a Nim program under Windows with `zig cc`:

C:\> nim c --cc:clang --clang.exe="zigcc.cmd" --clang.linkerexe="zigcc.cmd" main.nim

C:\> main.exe
hello nim

𝥶I use the Avast Antivirus, and when I launch this "main.exe", it starts immediately. When I compile with "nim c main.nim" and launch the EXE, the execution is blocked by Avast for about 20 seconds.

Cross-Compilation

Under Linux, let's create a Windows EXE that is less suspicious for the antivirus softwares:

$ nim c --cc:clang --clang.exe="zigcc" --clang.linkerexe="zigcc" \
  --passc:"-target x86_64-windows" --passl:"-target x86_64-windows" \
  --os:windows main.nim

$ wine main.exe
hello (linux -> windows)

See https://github.com/enthus1ast/zigcc if you want to cross-compile in the other direction: Windows → Linux.

Of course, if you want a smaller, faster EXE, then you can add the extra options/switches that we saw earlier here (like -d:release, etc.).

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 17, 19:04