You have the option of linking the stdlib dynamically if you set up your system accordingly (-d:useNimRtl). Note also that Nim already does dead code elimination with the command line option or the pragma (also implied by -d:release), so it will then only generate code for procedures and variables that are actually being used. Hello world still has a minimum size because the garbage collector and a few other basic things are always included.
That said, unless you're running your code on a toaster, there's really not much point to dynamic linking, except for frequently used system libraries, and dynamic linking has a lot of downsides.
Why does nim statically link everything?
Dynamic linking is possible: See
http://forum.nim-lang.org/t/679/1
http://forum.nim-lang.org/t/963#5822
I think 50 KB for a HelloWorld executable is really not bad for a high level language, which generally includes GC and other runtime code. For my tests clang gave smallest executables, even smaller with LTO enabled. But gcc executables may be faster in some cases. Yes, I think that Nim indeed compiles all included files currently. For examples when templates are used that may be necessary? But Nim compiler is already really fast, and C backend compiles only changed files.
How would I compile without the GC to get a smaller executable? I just want to see how small I can get it, and also, since it's just printing a string, it doesn't make sense to have a GC.
Stefan_Salewski: C backend compiles only changed files.
What does that mean?
You can safely turn it off for a hello world program. The code:
echo "Hello, world!"
will be translated (after optimization) into something like:
void hwInit() {
printf("%s\n", "Hello, world!");
}
(plus the general initialization boilerplate).
That said, I'm not sure why you'd want to turn the GC off for anything more complex.
$ cat t.nim echo "hello" Nim Compiler Version 0.11.0 (2015-05-03) [Linux: amd64] gcc version 4.9.2 clang version 3.6.0 nim c -d:release t.nim Executable size: 62032 bytes nim c --opt:size -d:release t.nim Executable size: 25208 bytes nim c --opt:size --gc:none -d:release t.nim Executable size: 14536 bytes nim c --cc:clang -d:release t.nim Executable size: 33392 bytes nim c --opt:size --cc:clang -d:release t.nim Executable size: 29296 bytes