haskell / c2hs

c2hs is a pre-processor for Haskell FFI bindings to C libraries
http://hackage.haskell.org/package/c2hs
Other
198 stars 50 forks source link

error on stdio (Sierra) #176

Closed RonVanderMeyden closed 7 years ago

RonVanderMeyden commented 7 years ago

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

schrammc commented 7 years ago

Is there a known workaround for this?

ian-ross commented 7 years ago

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/

kolmodin commented 7 years ago

@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.

sebeaumont commented 7 years ago

This is a show stopper for me on OSX any proper fix in the pipe?

kolmodin commented 7 years ago

@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.

deech commented 7 years ago

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.

sebeaumont commented 7 years ago

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.

deech commented 7 years ago

Ok I've found the two issues, and have been able to work around them. They are:

I successfully built my C2HS project by adding the following to the .cabal file:

    if os(darwin)
       cc-options: -U__BLOCKS__ -D_Nonnull=
ian-ross commented 7 years ago

@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...

deech commented 7 years ago

Should be fixed in 0.28.2.

sebeaumont commented 7 years ago

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.