|
Oktatás * Programozás 1 * Szkriptnyelvek Teaching * Programming 1 (BI) Félévek Linkek * kalendárium |
Nim2 /
Compiling a Nim program with zigInstall the "zigcc" Nim package that wraps $ 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-CompilationUnder 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 Links |
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |