Hi,

if I want to use the importc pragma, but the header containing the function I want only works properly, if prefixed by one or more other headers, how do I do this?

This is the example in the doc:

proc printf(formatstr: cstring) {.header: "<stdio.h>", importc: "printf", varargs.}
Run So, what if "<abc.h>" needed to be imported before "<stdio.h>"?

2018-01-12 07:52:28

header pragma allows multiple headers in the following way:

proc myProc() {.importc, header: """#include <abc.h>
                                  #include <stdio.h>""".}

It is worth noting that header pragma better be avoided as it makes your file dependent on the header. When function or struct ABI is well defined, you can easily get away with just importc pragma.

2018-01-12 08:17:53
Nice! I asked that in december, and got no reply... 2018-01-13 11:17:33