FFI and header files

482 views Asked by At

This is my directory structure:

C:.
│   lodepng.h
│   lodepng.c
│   nim.cfg
│   test.png
│   util.nim
│
└───nimcache

util nim is importing a c function from lodepng.h like this:

proc loadPNG(image: var ptr[cchar], width, height: var cuint, filename: cstring)
  {.importc: "lodepng_decode32_file", header: "lodepng.h".}

But the header is not copied into nimcache nor is found when compiling the code. How can i make sure nim compiler uses it?

1

There are 1 answers

0
Arrrrrrr On

I found the solution inside the nim backend integration guide:

{.compile: "lodepng.c".}
proc lodepng_decode32_file(image: var ptr[cchar], width, height: var cuint, filename: cstring): cuint {.importc.}