Questions tagged [c2hs]

c2hs is a generator tool for Haskell bindings to C libraries.

C->Haskell (c2hs) is an interfacing tool that assists in the development of Haskell FFI bindings to C libraries. It gathers interface information like data type definitions and function signatures from C header files and generates Haskell code with foreign imports.

There are some distinctions between c2hs and hsc2hs.

References

Related Tags

38 questions
100
votes
1 answer

Interfacing with structs and anonymous unions with c2hs

How would one go about encoding this chunk of C code in a .chs file so that c2hs can transform it to something relatively nice? typedef enum { MONOME_BUTTON_UP = 0x00, MONOME_BUTTON_DOWN = 0x01, MONOME_ENCODER_DELTA =…
user1908597
24
votes
2 answers

Difference between hsc2hs and c2hs?

What is the difference between hsc2hs and c2hs? I know what hsc2hs is a preprocessor but what does it exactly do? And c2hs can make Haskell modules from C-code, but do I need hsc2hs for this?
develhevel
  • 3,161
  • 4
  • 21
  • 27
22
votes
1 answer

Cabal install gtk failing

I'm trying to install gtk via cabal, however, I'm getting the following type errors when building it [ 22 of 209] Compiling Graphics.UI.Gtk.Embedding.Plug ( dist/build/Graphics/UI/Gtk/Embedding/Plug.hs, dist/build/Graphics/UI/Gtk/Embedding/Plug.o…
Matt
  • 4,029
  • 3
  • 20
  • 37
6
votes
1 answer

nvcc + c2hs on OS X 10.9.5

I'm building a software that needs nvcc for compilation. I don't have a CUDA-capable GPU, but actually I don't need that – a friend is building the exact same software on Linux, he has no CUDA GPU, but everything's fine. I installed the newest CUDA…
kgadek
  • 1,446
  • 1
  • 17
  • 18
6
votes
1 answer

How do I use Haddock with c2hs?

I am using c2hs to write some haskell bindings, and I would like to use Haddock to document automatically generated constructors and function parameters. However, c2hs ignores the comments; {#enum define WinPos { CA as HA -- ^ This comment is…
HaskellElephant
  • 9,819
  • 4
  • 38
  • 67
5
votes
1 answer

Can't get C2HS with "foreign" Pointers to work

General Information I'm currently experimenting with the C->Haskell (C2HS) Interface Generator for Haskell. At the first glace, it was just awesome, I interfaced a rather complicated C++ library (using a small extern C-wrapper) in just a couple of…
Johannes Weiss
  • 52,533
  • 16
  • 102
  • 136
4
votes
1 answer

inline-c : "`Type` cannot be marshalled in a foreign call"

Setting A C enum type rendered into Haskell by c2hs, complete with Storable instance which compiles correctly (TypesC2Hs.chs). I import this unqualified into the module I have assigned for the inline-c context (Internal.hs). Both the .hs module…
ocramz
  • 816
  • 6
  • 18
4
votes
1 answer

Returning a bare struct from C to Haskell in c2hs

I'm trying to bind to a C function that returns a struct (by value). I know I can wrap it manually using the FFI, but can't figure out how to coax c2hs into generating the correct code. It seems to think my function is returning a pointer. Here's a…
sinelaw
  • 16,205
  • 3
  • 49
  • 80
4
votes
1 answer

c2hs in- and out- type marshalling

I'm looking at the haskell-mpi binding, and we have e.g. this signature in mpi.h: int MPI_Initialized (int *flag); which in Internal.chs is represented as follows: {#fun unsafe Initialized as ^ {alloca- `Bool' peekBool*} -> `()' discard*- #} Q:…
ocramz
  • 816
  • 6
  • 18
3
votes
1 answer

What's the modern way to access C2HS marshalling functions?

I want to use the cFromEnum function, but this resides in the C2HS module, which I'm told is unnecessary and shouldn't be unpacked / installed ( c2hs not getting installed / registered correctly ). What's the modern way to convert an enum? For…
gatoatigrado
  • 16,580
  • 18
  • 81
  • 143
3
votes
2 answers

c2hs not getting installed / registered correctly

When I run cabal install c2hs, it seems to finish correctly, but doesn't register the package. The package seems as if it's not even installed: it doesn't show up in ghc-pkg list, and rerunning cabal install c2hs goes through the same install…
gatoatigrado
  • 16,580
  • 18
  • 81
  • 143
3
votes
0 answers

C2HS Pointer Type Correspondences

I have some conceptual questions about how C2HS generates type correspondences from {#pointer …} declarations. First, let ~ denote a type correspondence operator between C types and Haskell types. Then is it correct to say that {#pointer *CTypeName…
George
  • 6,927
  • 4
  • 34
  • 67
3
votes
1 answer

c2hs in marshaller vs. gtk2hsC2hs

i try to understand the difference between c2hs and gtk2hsC2hs (modified version of c2hs for use in gtk2hs). Consider the following coding: module Matrix where data Matrix = Matrix { xx :: !Double, yx :: !Double, xy ::…
kilian
  • 79
  • 4
3
votes
1 answer

How to call a C function that uses a callback in Haskell?

I am trying to call the following C function from Haskell using c2hs. void rd_kafka_conf_set_rebalance_cb ( rd_kafka_conf_t *conf, void (*rebalance_cb) (rd_kafka_t *rk, rd_kafka_resp_err_t err, …
Alexey Raga
  • 7,457
  • 1
  • 31
  • 40
3
votes
2 answers

do..while(0) function-like C macro wrapper in c2hs

I'd like to wrap a function-like C macro in a C function (and in turn wrap it in Haskell with a {#fun ... #} block), but the c2hs preprocessor chokes on the do.. while(0) syntax; here's the code: module TestMacro where #c #define TestF1(n) do{if…
ocramz
  • 816
  • 6
  • 18
1
2 3