PMunch / futhark

Automatic wrapping of C headers in Nim
MIT License
355 stars 19 forks source link

Futhark loses path to headers when importing #108

Closed crystalthoughts closed 3 weeks ago

crystalthoughts commented 3 weeks ago

Hi, I have a simple binding of a custom cimgui build:

import futhark

 importc:
    path "."
    path "./cimgui"
    define CIMGUI_DEFINE_ENUMS_AND_STRUCTS
    "cimgui.h"

{.passL:"-Icimgui.lib".}

It appears to work fine when compiling just this file, but if I import this in a parent file, I get: Fatal: 'cimgui.h' file not found. I'm sure I can edit the path but then if I import this in another place I imagine that would break too?

I'm also difficulty with getting outputPath to act reliably but perhaps that's another ticket :)

crystalthoughts commented 3 weeks ago

Is the correct solution: $currentSourcePath.parentDir / "cimgui.h" ?

If so I think it would really help people if this was mentioned in the docs :) I think the default assumption would be that the path is local to the source file.

PMunch commented 3 weeks ago

That is indeed the correct solution. I use that style in the docs in some places, but it's not very consistent. I guess it should be possible to change the working directory of Clang to where the Futhark macro was called from, that would make paths behave a bit better.

crystalthoughts commented 3 weeks ago

I'm also getting undeclared identifier when trying to use any of the header functions/types in this case, like imvec2() or echoing an enum value. Could it be a silent linker path error?

Do I need to include the generated nim file before use?

crystalthoughts commented 3 weeks ago

and thanks!

crystalthoughts commented 3 weeks ago

I can pad out the docs in the future with a pull request if you're interested