> What in particular needs work on Windows 64bit?

libffi bindings only support win32, not win64; maybe a solution is to use a dll 
for win64 instead of embedding the sources, see 
[https://github.com/Araq/libffi/blob/master/libffi.nim#L14](https://github.com/Araq/libffi/blob/master/libffi.nim#L14)

> Is there a way that you currently use to import a C macro from a header file 
> at compile time?

not that I know of but the following works:
    
    
    when defined(timn_D20191211T153325):
      {.emit:"""
      // or: # include "temp.h" which would contain these macros:
      #define MAX(a,b) ((a < b) ?  (b) : (a))
      #define MY_CONST1 "asdf"
      #define MY_CONST2 23
      
      // instantiate these macros to get concrete symbols
      N_LIB_EXPORT int MAX_int(int a, int b){ return MAX(a, b);}
      N_LIB_EXPORT char* get_MY_CONST1(){return MY_CONST1;}
      N_LIB_EXPORT int get_MY_CONST2(){return MY_CONST2;}
      """.}
    
    else:
      import std/[strformat,os,strutils]
      const libF = "/tmp/" / (DynlibFormat % "D20191211T153325")
      const nim = getCurrentCompilerExe()
      const file = currentSourcePath()
      static:
        let cmd = fmt"{nim} c -d:timn_D20191211T153325 --app:lib -o:{libF} 
{file}"
        echo cmd
        let (output, exitCode) = gorgeEx cmd
        doAssert exitCode == 0, output
      
      proc MAX_int(a, b: int): int {.importc, dynlib: libF.}
      proc MY_CONST1(): cstring {.importc: "get_MY_CONST1", dynlib: libF.}
      proc MY_CONST2(): cint {.importc: "get_MY_CONST2", dynlib: libF.}
      
      proc main()=
        doAssert MAX_int(2, 3) == 3
        doAssert MY_CONST1() == "asdf"
        doAssert MY_CONST2() == 23
      
      static: main()
      main()
    
    
    Run

Reply via email to