Compile pragma

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

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

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 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.