Problem:
1. On OSX, FLTK (FLTK 1.3 shapshot 8048, and earlier too) includes draw in OSX
specific Objective-C/C++ 2.0 include files, that can only be compiled with
Apple supplied GCC variants. Apple-GCC seems to be stuck at versions 4.0 and
4.2.
2. The included OSX headers also cause name collisions with some software that
has not been designed to include OSX-specific header files. For example, there
is a name collision with "Cell" as defined by the included OSX headers and
"Cell" defined in GNU Octave. (This at least when compiling 64-bit, have not
tested this with 32-bit.)
3. It would be great if it was possible to use FLTK also with non-Apple GCC
versions, especially when compiling portable (non-OSX) code, that relies on
FLTK for UI portability (which I presume is the whole point with FLTK !)
Solution:
Obviously FLTK needs to USE Objective-C to implement the OSX specific stuff,
but that should not be exposed to the user of FLTK. I found out that FLTK file
FL/mac.H includes <Carbon/Carbon.h>, even though the definitions in that file
only use a very, very small fraction of the stuff drawn in. In the same spirit
that FL/mac.H already defined CGFloat (if needed), I tested if the few needed
definitions could be done in FL/mac.H directly, so that FLTK applications would
not have to be compiled with a Objective-C 2.0 compatible compiler.
The resulting FL/mac.H diff is below. To use FLTK without including OSX
includes, you should have the symbol __CARBON__ defined. For compiling GNU
Octave I added "-D__CARBON__" into FLTK_CFLAGS in Octave's configure.ac. Having
__CARBON__ defined makes #include <Carbon/Carbon.h> (in FL/mac.H) to have no
effect and the additions to FL/mac.H (below) kick in.
The setting of MAC_OS_X_VERSION_MAX_ALLOWED to MAC_OS_X_VERSION_10_3 (as in the
original FL/mac.H) caused an error on 64-bit builds. To remedy this I changed
FL/mac.H to include <AvailabilityMacros.h>, which properly handles all
MAC_OS_X_VERSION_XXX macros. AvailabilityMacros.h is available since OSX 10.2,
so with this compilation fails on 10.0 and 10.1, but I guess that is OK, as
they do not have Cocoa either.
AvailabilityMacros.h contains no Objective-C/C++ code, so it works with all
C/C++ compilers.
Obviously, when compiling FLTK itself (with Apple GCC, no less), "__CARBON__"
should not be defined in advance. In this case none of the changes in FL/mac.H
have any effect.
With these changes the above mentioned "Cell" symbol clash also disappears (as
OSX headers are not included), and Octave compiles and runs with FLTK backend,
even when compiled with non-Apple GCC.
Now I have exactly the same behavior for FLTK as before using Apple GCC 4.2,
but now using GCC 4.5.1 instead.
I have also provided a simplified "makeinclude" to be used with fltk examples
(you need to edit examples/Makefile to point to this makeinclude instead).
Please see below.
Please feel free to add these changes to FLTK, if you see portable support for
non-Apple compilers useful in OSX.
Regards,
Jarno Rajahalme
Diffs from a recent weekly FLTK 1.3 shapshot (8048) FL/mac.H:
$ diff -c fltk-1.3.x-r8048/FL/mac.H /opt/local/include/FL/mac.H
*** fltk-1.3.x-r8048/FL/mac.H Wed Dec 1 19:48:59 2010
--- /opt/local/include/FL/mac.H Wed Dec 22 10:45:53 2010
***************
*** 38,56 ****
#include <Carbon/Carbon.h>
#ifndef MAC_OS_X_VERSION_10_3
! #define MAC_OS_X_VERSION_10_3 1030
! #endif
! #ifndef MAC_OS_X_VERSION_10_4
! #define MAC_OS_X_VERSION_10_4 1040
! #endif
! #ifndef MAC_OS_X_VERSION_10_5
! #define MAC_OS_X_VERSION_10_5 1050
! #endif
! #ifndef MAC_OS_X_VERSION_10_6
! #define MAC_OS_X_VERSION_10_6 1060
! #endif
! #ifndef MAC_OS_X_VERSION_MAX_ALLOWED
! #define MAC_OS_X_VERSION_MAX_ALLOWED MAC_OS_X_VERSION_10_3
#endif
#ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h
--- 38,46 ----
#include <Carbon/Carbon.h>
#ifndef MAC_OS_X_VERSION_10_3
! // All MAC_OS_X_VERSION_ macros are properly defined in AvailabilityMacros.h,
! // which exists since OSX 10.2
! #include <AvailabilityMacros.h>
#endif
#ifndef CGFLOAT_DEFINED //appears with 10.5 in CGBase.h
***************
*** 61,66 ****
--- 51,92 ----
#endif
#endif // CGFLOAT_DEFINED
+ #ifndef CGGEOMETRY_H_ // CoreGraphics/CGGeometry.h
+ struct CGPoint {
+ CGFloat x;
+ CGFloat y;
+ };
+ typedef struct CGPoint CGPoint;
+ struct CGSize {
+ CGFloat width;
+ CGFloat height;
+ };
+ typedef struct CGSize CGSize;
+ struct CGRect {
+ CGPoint origin;
+ CGSize size;
+ };
+ typedef struct CGRect CGRect;
+ #endif /* CGGEOMETRY_H_ */
+
+ #ifndef CGCONTEXT_H_ // CoreGraphics/CGContext.h
+ typedef struct CGContext *CGContextRef;
+ #endif /* CGCONTEXT_H_ */
+
+ #ifndef CGIMAGE_H_ // CoreGraphics/CGImage.h
+ typedef struct CGImage *CGImageRef;
+ #endif /* CGIMAGE_H_ */
+
+ #ifndef __QUICKDRAWTYPES__ // QD/QuickdrawTypes.h
+ typedef struct OpaqueWindowPtr* WindowPtr;
+ typedef WindowPtr WindowRef;
+ struct RGBColor {
+ unsigned short red;
+ unsigned short green;
+ unsigned short blue;
+ };
+ typedef struct RGBColor RGBColor;
+ #endif /* __QUICKDRAWTYPES__ */
// Now make some fixes to the headers...
#undef check // Dunno where this comes from...
$
Simple makeinclude file to be used with fltk examples (NOT with fltk itself!).
Place in fltk/examples/ folder and edit fltk/examples/Makefile to point to this
instead of ../makeinclude.
#
# Minimal makeinclude file for fltk examples
#
# Demonstrating use of (macports) GCC 4.5 for building FLTK 1.3 applications,
# while FLTK itself has been built with Apple GCC 4.2
# (required for OSX Objective-C/C++ 2.0 support).
#
# Likely requires FLTK to be linked as a dynamic library.
#
# compiler names: GCC 4.5 via macports
CXX = g++-mp-4.5
CC = gcc-mp-4.5
#
# Non-Apple GCC does not support "-arch", using "-m64" instead
#
# We use -D__CARBON__ so that OSX (Objective-C/C++ 2.0) includes are NOT
included by FL/mac.H
#
# flags for C++ compiler:
ARCHFLAGS = -m64
OPTIM = -O3
CFLAGS = $(OPTIM) -D__CARBON__
CXXFLAGS = $(OPTIM) -D__CARBON__
#
# Note: No need to specify ANY OSX specific libraries!
# /opt/local/lib is where fltk library installed via macports is found
#
# libraries to link with:
LDFLAGS = $(OPTIM) -L/opt/local/lib
LDLIBS = -lpthread
LINKFLTK = -lfltk
EXEEXT =
# Be quiet when building...
#.SILENT:
# Build commands and filename extensions...
.SUFFIXES: .c .cxx .h .o $(EXEEXT)
.o$(EXEEXT):
echo Linking $...@...
$(CXX) $(ARCHFLAGS) $(LDFLAGS) $< $(LINKFLTK) $(LDLIBS) -o $@
.c.o:
echo Compiling $<...
$(CC) $(ARCHFLAGS) $(CFLAGS) -c $< -o $@
.cxx.o:
echo Compiling $<...
$(CXX) $(ARCHFLAGS) $(CXXFLAGS) -c $< -o $@
Example compilation:
$ make
echo Compiling howto-add_fd-and-popen.cxx...
Compiling howto-add_fd-and-popen.cxx...
g++-mp-4.5 -m64 -O3 -D__CARBON__ -c howto-add_fd-and-popen.cxx -o
howto-add_fd-and-popen.o
echo Linking howto-add_fd-and-popen...
Linking howto-add_fd-and-popen...
g++-mp-4.5 -m64 -O3 -L/opt/local/lib howto-add_fd-and-popen.o -lfltk -lpthread
-o howto-add_fd-and-popen
echo Compiling howto-parse-args.cxx...
Compiling howto-parse-args.cxx...
g++-mp-4.5 -m64 -O3 -D__CARBON__ -c howto-parse-args.cxx -o howto-parse-args.o
echo Linking howto-parse-args...
Linking howto-parse-args...
g++-mp-4.5 -m64 -O3 -L/opt/local/lib howto-parse-args.o -lfltk -lpthread -o
howto-parse-args
echo Compiling howto-text-over-image-button.cxx...
Compiling howto-text-over-image-button.cxx...
g++-mp-4.5 -m64 -O3 -D__CARBON__ -c howto-text-over-image-button.cxx -o
howto-text-over-image-button.o
echo Linking howto-text-over-image-button...
Linking howto-text-over-image-button...
g++-mp-4.5 -m64 -O3 -L/opt/local/lib howto-text-over-image-button.o -lfltk
-lpthread -o howto-text-over-image-button
echo Compiling menubar-add.cxx...
Compiling menubar-add.cxx...
g++-mp-4.5 -m64 -O3 -D__CARBON__ -c menubar-add.cxx -o menubar-add.o
echo Linking menubar-add...
Linking menubar-add...
g++-mp-4.5 -m64 -O3 -L/opt/local/lib menubar-add.o -lfltk -lpthread -o
menubar-add
echo Compiling table-as-container.cxx...
Compiling table-as-container.cxx...
g++-mp-4.5 -m64 -O3 -D__CARBON__ -c table-as-container.cxx -o
table-as-container.o
echo Linking table-as-container...
Linking table-as-container...
g++-mp-4.5 -m64 -O3 -L/opt/local/lib table-as-container.o -lfltk -lpthread -o
table-as-container
echo Compiling table-simple.cxx...
Compiling table-simple.cxx...
g++-mp-4.5 -m64 -O3 -D__CARBON__ -c table-simple.cxx -o table-simple.o
echo Linking table-simple...
Linking table-simple...
g++-mp-4.5 -m64 -O3 -L/opt/local/lib table-simple.o -lfltk -lpthread -o
table-simple
echo Compiling table-sort.cxx...
Compiling table-sort.cxx...
g++-mp-4.5 -m64 -O3 -D__CARBON__ -c table-sort.cxx -o table-sort.o
echo Linking table-sort...
Linking table-sort...
g++-mp-4.5 -m64 -O3 -L/opt/local/lib table-sort.o -lfltk -lpthread -o
table-sort
echo Compiling table-spreadsheet.cxx...
Compiling table-spreadsheet.cxx...
g++-mp-4.5 -m64 -O3 -D__CARBON__ -c table-spreadsheet.cxx -o table-spreadsheet.o
echo Linking table-spreadsheet...
Linking table-spreadsheet...
g++-mp-4.5 -m64 -O3 -L/opt/local/lib table-spreadsheet.o -lfltk -lpthread -o
table-spreadsheet
echo Compiling table-spreadsheet-with-keyboard-nav.cxx...
Compiling table-spreadsheet-with-keyboard-nav.cxx...
g++-mp-4.5 -m64 -O3 -D__CARBON__ -c table-spreadsheet-with-keyboard-nav.cxx -o
table-spreadsheet-with-keyboard-nav.o
echo Linking table-spreadsheet-with-keyboard-nav...
Linking table-spreadsheet-with-keyboard-nav...
g++-mp-4.5 -m64 -O3 -L/opt/local/lib table-spreadsheet-with-keyboard-nav.o
-lfltk -lpthread -o table-spreadsheet-with-keyboard-nav
echo Compiling tabs-simple.cxx...
Compiling tabs-simple.cxx...
g++-mp-4.5 -m64 -O3 -D__CARBON__ -c tabs-simple.cxx -o tabs-simple.o
echo Linking tabs-simple...
Linking tabs-simple...
g++-mp-4.5 -m64 -O3 -L/opt/local/lib tabs-simple.o -lfltk -lpthread -o
tabs-simple
echo Compiling textdisplay-with-colors.cxx...
Compiling textdisplay-with-colors.cxx...
g++-mp-4.5 -m64 -O3 -D__CARBON__ -c textdisplay-with-colors.cxx -o
textdisplay-with-colors.o
echo Linking textdisplay-with-colors...
Linking textdisplay-with-colors...
g++-mp-4.5 -m64 -O3 -L/opt/local/lib textdisplay-with-colors.o -lfltk -lpthread
-o textdisplay-with-colors
echo Compiling texteditor-simple.cxx...
Compiling texteditor-simple.cxx...
g++-mp-4.5 -m64 -O3 -D__CARBON__ -c texteditor-simple.cxx -o texteditor-simple.o
echo Linking texteditor-simple...
Linking texteditor-simple...
g++-mp-4.5 -m64 -O3 -L/opt/local/lib texteditor-simple.o -lfltk -lpthread -o
texteditor-simple
echo Compiling tree-simple.cxx...
Compiling tree-simple.cxx...
g++-mp-4.5 -m64 -O3 -D__CARBON__ -c tree-simple.cxx -o tree-simple.o
echo Linking tree-simple...
Linking tree-simple...
g++-mp-4.5 -m64 -O3 -L/opt/local/lib tree-simple.o -lfltk -lpthread -o
tree-simple
echo Compiling wizard-simple.cxx...
Compiling wizard-simple.cxx...
g++-mp-4.5 -m64 -O3 -D__CARBON__ -c wizard-simple.cxx -o wizard-simple.o
echo Linking wizard-simple...
Linking wizard-simple...
g++-mp-4.5 -m64 -O3 -L/opt/local/lib wizard-simple.o -lfltk -lpthread -o
wizard-simple
rm menubar-add.o howto-text-over-image-button.o wizard-simple.o table-simple.o
howto-parse-args.o table-spreadsheet-with-keyboard-nav.o table-as-container.o
tree-simple.o table-sort.o textdisplay-with-colors.o table-spreadsheet.o
tabs-simple.o texteditor-simple.o howto-add_fd-and-popen.o
$
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev