Using --header:HEADER_FILE results in bad .nim code
Simple test.h file
int function(int param);
Processed with c2nim --header:test.h test.h results in bad .nim code - no quotes around the header file in the pragma.
proc function*(param: cint): cint {.importc: "function", header: test.h.}
Both --header:"test.h" or --header:\"test.h\" don't work either.
Processed with c2nim --header test.h without specifying HEADER_FILE works correctly but isn't useful for my purposes.
proc function*(param: cint): cint {.importc: "function", header: "test.h".}
I think I understand the intent of this flag - it is similar to --dynlib where the value following the : is to be treated as a const that needs to be defined in the resulting file.
So if you have c2nim --header:headerfile test.h, you get:
const headerfile = "test.h"
proc function*(param: cint): cint {.importc: "function", header: headerfile.}
where the const was added manually, after the fact.
I'm thinking this should be left open to be either:
- Fixed in documentation
- Updated to allow entering a static string for both --header: and --dynlib: (if in quotes) in case you want to hard code a value and not require manual editing.
Or it could be closed as working as designed. I'll let you decide what's the appropriate approach.
Both --header:"test.h" or --header:"test.h" don't work either.
That's because the shell interprets the double-quotes. To pass them through to c2nim you have to wrap them in single-quotes, which in most shells completely disables shell processing:
c2nim --header '"test.h"' test.h
This works for me in a bash script.