[Gllug] cross platform development (C++)

Steve Goodwin SteveG at bitscorp.com
Wed Jun 19 13:04:05 UTC 2002


> what I really want to do is compile one set of sources to 
> produce executables 
> for each of Windows and Linux (preferably Mac OS too)

Being pedantic for a moment, is that what you want to do? Or do you want the
same _program_ on both platforms?

Since they have Windows machines with licenses you might do better (in the
long run) to work at home, and re-compile a similar (but not necessarily
identical) code base at uni using native tools. This will invariably give
better performance/debugging capabilities than cross over tools.

With console apps, just stick to standard ANSI input/output, or standard
libraries that exist on both (certainly not MSVCRT et al).

With graphical apps, I'd create an abstraction layer regardless of the
underlying toolkit you are using, or plan to use. Create your own class for
each platform, inheritted from an abstract base that includes the basic
create window/button/text functionality. 

class CInterface {
	virtual HMYHANDLE	CreateWindow(int w, int h...);
	virtual HMYHANDLE	CreateButton(HMYHANDLE hParent, int x, int
y...);
	.. etc ..
	};

then
	class CWindowsInterface : public CInterface {	...
or
	class CLinuxInterface : public CInterface {	...

Depending on the platform, create a new instance,

CInterface *pInterface;

#ifdef _WINDOWS
	pInterface = (CInterface *)new CWindowsInterface ;
#else
	pInterface = (CInterface *)new CLinuxInterface ;
#endif

You can then reference all the functions through the base pointer,

	pInterface->CreateWindow(...

and everything works naturally.

You can then write your QT functions (all wrapped up) in your CInterface
class implementation, and repeat for Windows, using whatever
license/style/code is available at the time. This also helps future
proofing, as the underlying library can change, without modifying the app.

Creating a good set of abstract functions is difficult. I'd recommend
looking at two or three possible setups, and make a version that works
cleanly with all of them. Since you are trying to adopt two philosphies into
one API, things don't always fit nicely so instead of fretting over
something 100% abstract make it 100% abstract for the known cases, and lever
the others in later!


The Mozzilla thing looks interesting, but since it'll be driving an external
application (that will rarely have been an exact port) I'm not sure how
extensively it will be used for cross platforming. 

Any one?

Steev

> 
> I'd like to be able to do this for GUI stuff as well as console ...
> 
> having looked around this looks non-trivial
> 
> I'm not really clear on how to compile a Windows execuatable 
> on a Linux host
> 
> ( http://www.mingw.org/index.shtml - seems to be a starting point )
> 
> and GUI stuff seems even trickier
> 
> Qt is nice but the Windows/Mac license isn't (and it looks 
> like you have to do 
> the compile on the right platform anyway)
> 
> GTK seems ugly, C based and again I'm not sure if I have to 
> use Win host for 
> Win output (but it is Gnu)
> 
> Mozilla XUL looks interesting (it *looks* like it can be used 
> for creating 
> UI's for random applications) but it's new and lacking in 
> documentation.
> 
> advice anyone...
> 
> - -- 
> 
> Sean
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.6 (GNU/Linux)
> Comment: For info see http://www.gnupg.org
> 
> iD8DBQE9D4maFw+p23sRiPURAtlzAJ4khQ3oNH9tw+W1GwLMXXSWslCD9gCgjHkC
> 5iOcRjsnCNRqZuoMLhJLjck=
> =ED4w
> -----END PGP SIGNATURE-----
> 
> 
> 
> -- 
> Gllug mailing list  -  Gllug at linux.co.uk
> http://list.ftech.net/mailman/listinfo/gllug
> 



The information in this Internet Email is confidential and is intended
solely for the addressee. Access, copying or re-use of information in it by
anyone else is unauthorised. Please immediately notify the sender if you are
not the intended recipient and have received this mail. 
Any views or opinions presented are solely those of the author and do not
necessarily represent those of Bits Corp plc or any of its affiliates. 

Tel. +44 (0)20 8282 7200 
Fax. +44 (0)20 8450 9966


-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list