On 12.02.2016 08:49 David Topham wrote:
> Thanks Ian, for taking the time to help with this...I added the include
> of config.h in a FLUID declaration because without it, the program does
> not build. I also need to to remove the include of FL/Fl.H in an editor
> after FLUID creates the files.
>
> Here is the output from trying to build with FL/Fl.H and config.h
> included (in tryit.h created by FLUID)
>
>
http://ix.io/olk
>
> (is method appropriate to posting error messages?)
It would be better to attach a text file (not an image/screenshot) to
the message you are posting so we have the message available even if the
external reference will be removed later. An attachment is preferred
over inlined messages because it keeps formatting intact.
> These are the errors if I do not include config.h
>
>
http://ix.io/oln
>
> But, without FL/Fl.H and with config.h, it builds fine using this
>
> fltk-config --use-cairo --compile tryit.cxx
Okay, that's fine (somewhat), but doesn't help for larger programs with
multiple source files.
However, I found a solution - or better - workaround. The culprit lies
in the FLTK header files that require config.h, but this should never be
included in user source files, because it will not be available as an
installed header file (as Ian mentioned).
Here is my modified tryit.h file:
#ifndef tryit_h
#define tryit_h
#if 0
// Solution #1 (bad) - #include <config.h> BEFORE FL/Fl.H
// #include <config.h>
#else
// Solution #2 (still bad, but better)
#define FLTK_HAVE_CAIRO
#define USE_X11
#endif
#include <FL/Fl.H>
#include <FL/Fl_Cairo_Window.H>
void cwcb(Fl_Cairo_Window* cw,cairo_t* cr);
extern Fl_Cairo_Window *cw;
#endif
Comments:
I used both "solutions" successfully under Linux.
Solution #1 includes <config.h> before (!) Fl.H. This enables some
conditional code in Fl.H. This is bad, and FLTK should be fixed. This
will likely be addressed in FLTK 1.4
Solution #2 is my recommended workaround for now. You need
#define FLTK_HAVE_CAIRO
(again: before any other FLTK header files) to enable cairo support in
the FLTK headers.
You do also need to define a platform macro so FLTK "knows" which cairo
headers to #include. USE_X11 is needed for all U*x (Linux) platforms,
but again this is a questionable way (IMHO FLTK's fault). You can take a
look at FL/Fl_Cairo.H and see how this is done. I suggest to
#include <whatever-cairo.h>
in your user code so you don't need to define USE_X11, WIN32, or
__APPLE_QUARTZ__ (the platform macros used in the FLTK lib and defined
in config.h), but this might still fail because of that (IMHO wrong)
error message if no applicable platform macro is defined.
So, having said all that, I believe that we need to fix the FLTK headers
and document a proper way to use Fl_Cairo_Window with FLTK. I suggest to
use workaround (solution) #2 meanwhile.
HTH
Albrecht