配置Nim的默认编译参数 release build并运行

默认情况下nim编译是debug build,如果需要release build, 需要加上-d:release ,
release编译的命令如下:
nim c -d:release xx.nim

release build并运行:
nim c -r -d:release xx.nim

debug build出来可执行文件体积稍大,并且目前对来我说没有用。

我发现通过配置nim.cfg,可以给nim编译器配置默认的编译参数,nim.cfg文件位于nim的安装目录/config下。

类似如下在nim.cfg中添加参数r和d:release,一行一个参数:

# Configuration file for the Nim Compiler.
# (c) 2017 Andreas Rumpf

# Feel free to edit the default values as you need.

# You may set environment variables with
# @putenv "key" "val"
# Environment variables can be accessed like so:
#  gcc.path %= "$CC_PATH"

cc = gcc
r
d:release
...
...
...

之后当你执行nim c xx.nim的时候,配置文件中参数自动传送给Nim编译器:
等于 nim c -r -d:release xx.nim

2018-01-18 18:30:00 codegay