Closed RonVanderMeyden closed 7 years ago
Is there a known workaround for this?
Not that I know. Errors like this are usually down to C syntax features unsupported by the language-c
package (which is what C2HS uses to parse header files). The best way to get movement on issues like these is probably to make a small test case and submit it as an issue to the language-c
maintainers: https://github.com/visq/language-c/issues/
@kryoxide The only workaround I know is to define these variables to empty strings. Not sure if it's guaranteed to work since you may end up with invalid C code, but it worked in my project. See https://github.com/grpc/grpc-haskell/issues/6.
This is a show stopper for me on OSX any proper fix in the pipe?
@sebeaumont Not that I know. If somebody with a Mac could follow @ian-ross suggestion in https://github.com/haskell/c2hs/issues/176#issuecomment-270351933 that would be a good first step.
At least one issue I'm seeing off the bat is the language-c
doesn't know how to parse Apple's block syntax, (^ ...)
, but they are always between __BLOCKS__
so I'm looking into seeing if these can be ignored by c2hs
by passing a flag.
Yes I've found a few more things - I'm thinking c-language only supports c90 - since I've full control over headers I'm using to I/f library so I'm taking a defensive approach and working around these things now. Once I've worked out the marshalling I will probably go back to using vanilla Haskell FFI and doing it by hand. In the meantime I'll enforce some c90 tests on my headers and take it from there.
Ok I've found the two issues, and have been able to work around them. They are:
(^ ...)
_Nonnull
keyword in headers, eg.
void *bsearch(const void *__key, const void *__base, size_t __nel,
size_t __width, int (* _Nonnull __compar)(const void *, const void *));
I successfully built my C2HS project by adding the following to the .cabal
file:
if os(darwin)
cc-options: -U__BLOCKS__ -D_Nonnull=
@deech That preprocessor undefine to deal with the blocks thing should already be there (https://github.com/haskell/c2hs/blob/master/src/Main.hs#L580). That was one of the few OS X specific things I managed to find an easy workaround for...
Thanks very much. Currently I've sidestepped these issues so as to proceed with 0.28.2 I can go back and undo my workarounds.
After an upgrade to OSX Sierra, I see the following ...
c2hs: C header contains errors: /usr/include/stdio.h:133: (column 19) [ERROR] >>> Syntax error ! The symbol `_close' does not fit here.
It seems others have hit this issue as well, as yet unresolved as far as I can see. See https://github.com/tweag/HaskellR/issues/275