Difference between revisions of "Writing portable code"
Line 9: | Line 9: | ||
GNUstep Base and the FoundationKit offer many parts of the CoreFoundation functionality in a natural Objective-C manner. | GNUstep Base and the FoundationKit offer many parts of the CoreFoundation functionality in a natural Objective-C manner. | ||
− | + | When you need to distinguish between Cocoa and GNUstep, you may use the following | |
#ifdef GNUSTEP | #ifdef GNUSTEP | ||
Line 16: | Line 16: | ||
''/* OS-X Cocoa native code goes here ... */'' | ''/* OS-X Cocoa native code goes here ... */'' | ||
#endif | #endif | ||
+ | |||
+ | Replace your include of <Cocoa/Cocoa.h> with the following, which will also work on OS-X: | ||
+ | |||
+ | #import <Foundation/Foundation.h> | ||
+ | #import <AppKit/AppKit.h> | ||
+ | |||
''' ''FIXME: add following:'' ''' | ''' ''FIXME: add following:'' ''' | ||
− | * how to port interface (.nib) files | + | * how to port interface (.nib) files using [http://freshmeat.net/projects/nib2gmodel/ nib2gmodel] |
− | * how to convert xCode project to GNUstep project ( | + | * how to convert xCode project to GNUstep project (creating a GNUstep [http://www.gnustep.it/nicola/Tutorials/WritingMakefiles/index.html Makefile] or [[ProjectCenter]]) |
== Notes == | == Notes == |
Revision as of 13:04, 3 March 2005
GNUstep opens up some fairly interesting opportunities to target a number of platforms with the same source code, for example porting MacOS X Cocoa applications to Linux, the BSDs, other Unices and (ultimately) Windows without significant re-engineering effort or degraded end-user functionality.
Some portability gotchas are listed below (please update when you run into a new one!):
MacOS X to GNUstep
OS-X developers should try and avoid CoreFoundation as this will complicate your dependency situation on non-Mac hosts, even if that part of CoreFoundation has actually been ported.
GNUstep Base and the FoundationKit offer many parts of the CoreFoundation functionality in a natural Objective-C manner.
When you need to distinguish between Cocoa and GNUstep, you may use the following
#ifdef GNUSTEP /* GNUstep code goes here ... */ #else /* OS-X Cocoa native code goes here ... */ #endif
Replace your include of <Cocoa/Cocoa.h> with the following, which will also work on OS-X:
#import <Foundation/Foundation.h> #import <AppKit/AppKit.h>
FIXME: add following:
- how to port interface (.nib) files using nib2gmodel
- how to convert xCode project to GNUstep project (creating a GNUstep Makefile or ProjectCenter)
Notes
Do not rely on tools available in development environment
All the world is not Linux or FreeBSD or Windows. System constants may be different on different platforms. Paths to command-line tools, the parameters they accept and locations of temporary directories may be different to what you are used to on your platform.
- GNUstep Base and the FoundationKit offer some of this functionality "for free".
- Try not to hard code paths and so on into your code, use macros (not recommended), or even better an abstraction mechanism.
- Avoid hard-coding system constants, or platform-specific ones where Posix or commonly-accepted ones exist (and we're not talking about glibc here :-)