Compile pragma

The compile pragma can be used to compile and link a C/C++ source file with the project:

This pragma can take three forms. The first is a simple file input:

  1. {.compile: "myfile.cpp".}

The second form is a tuple where the second arg is the output name strutils formatter:

  1. {.compile: ("file.c", "$1.o").}

Note: Nim computes a SHA1 checksum and only recompiles the file if it has changed. One can use the -f command-line option to force the recompilation of the file.

Since 1.4 the compile pragma is also available with this syntax:

  1. {.compile("myfile.cpp", "--custom flags here").}

As can be seen in the example, this new variant allows for custom flags that are passed to the C compiler when the file is recompiled.