Closed dinau closed 1 year ago
There are really a couple of questions here. To start lets address the error you get. That "undefined reference to sayHello
is from the C compiler because it doesn't know that it should link against hello.dll
. This can be fixed by passing in the correct linker flags with passL
, either as a switch or as a pragma. For example on Linux (where I named the library libhello.so
) I added {.passL: "-L. -lhello".}
and the compilation went well. On Linux you also need to call it as LD_LIBRARY_PATH=. ./test
because it doesn't load dynamic libraries from the current path by default, but I believe this isn't an issue with Windows. You can also throw this switch on the compilation nim c --passL:"-L. -lhello" test
.
The only thing the dynlib
pragma does is to automatically pass these flags during compilation when the procedures are used. The way you can add these built-in pragmas to everything in the Futhark generated output is to use the {.push.}
and {.pop.}
pragmas like this:
{.push dynlib: "hello.dll".}
when defined(useFuthark):
import futhark
importc:
path "."
"hello.h"
outputPath "helloDef.nim"
else:
include "helloDef.nim"
{.pop.}
sayHello()
This essentially applies the pragma to everything between the push and the pop, and they apply to the output of the importc and the include. Unfortunately this doesn't apply to custom pragmas from macros, but you can apply those with a macro that takes a typed
input.
I've tried these simplified steps,
Make hello.c
Make
hello.dll
hello.h
test.nim
Generate
helloDef.nim
I'd like to run only using
helloDef.nim
and hello.dll as follows;but the error occured.
Generated
helloDef.nim
I'd like to add
dynlib:"hello.dll"
pargma orpragma pragma
(for flexibility)to
sayhello*
proc.How to add extra
pragmas
using Futhark directives in this case ?