deech / fltkhs

Haskell bindings to FLTK GUI toolkit.
MIT License
190 stars 24 forks source link

GL causes c2hs error on Mac due to missing type #149

Closed mtolly closed 5 years ago

mtolly commented 5 years ago

If I clone current master (c55aa919) and edit stack.yaml with

flags:
  fltkhs:
    bundled: true
    opengl: true

on Linux everything builds fine and I get a working GL demo app. But on Mac I get:

*** Linking libfltkc-dyn.dylib...
Preprocessing library for fltkhs-0.8.0.2..
c2hs: Errors during expansion of binding hooks:

src/Graphics/UI/FLTK/LowLevel/Fl_Types.chs:376: (column 28) [ERROR]  >>> Unknown identifier!
  Cannot find a definition for `GLContext' in the header file.

I think this is because in platform_types.h there's this (line 89):

#ifdef __APPLE__
typedef struct CGContext* Fl_Offscreen;
typedef struct CGImage* Fl_Bitmask;
typedef struct flCocoaRegion* Fl_Region;
typedef int FL_SOCKET;
#ifdef __OBJC__
  @class NSOpenGLContext;
  typedef NSOpenGLContext* GLContext;
#elif defined(__cplusplus)
  typedef class NSOpenGLContext* GLContext;
#endif /* __OBJC__ */

So the type is defined for Objective C and C++, but not the C context c2hs uses. I added

#else
  typedef struct NSOpenGLContext* GLContext;

rezipped fltk-master.zip and it works. I'm not sure the best way to fix it for real though, is there a way to patch the file after unzipping? Or could the definition go somewhere else like Fl_Types.h?

deech commented 5 years ago

Can you try https://github.com/deech/fltkhs/tree/macOSGLContext? I'll merge it into master if it works for you.

mtolly commented 5 years ago

I needed to add

#include "Fl_Gl_WindowC.h"

to the includes at the top of Fl_Types.chs, and I also needed a semicolon at the end of

typedef struct NSOpenGLContext* GLContext;

and then it works.

deech commented 5 years ago

If you already have that fix in place locally do you mind PR'ing that to the branch. Appreciate your patience.

mtolly commented 5 years ago

PR at #150 . Thank you for the quick fix!