Re: Compatible codes for both Visual Studio 2005 and gcc
On Sep 23, 7:16 pm, "Phlip" <phlip...@yahoo.com> wrote:
Alexander Dong Back Kim wrote:
I'm doing an experimental thing that the codes I wrote can be compiled
by both VS2005 and gcc. I saw somewhere on the web that I can use
compiler's pre-defined value something life "_cplusplus_" or
"_win32_". My question is is there any way that I can make codes that
can be compiled by the both beautiful compilers? Any comments or
suggestions would be much appreciated.
I would do that by installing CygWin, to get a complete bash environment,
with its GCC.
There are at least three "Unix-like" environments for Windows:
CygWin, UWin and MSys. From experience, I'd avoid CygWin. MSys
is probably the lightest weight, and the best solution for
someone only using it for compatibility issues, UWin gives a
more completely Unix look-and-feel, but doesn't integrate into
Windows as well. And CygWin is just a disaster on all levels.
But I'm not sure that that's the question (and if it was, it
wouldn't really be relevant here). The question is how to write
compatible C++, which will compile with both
compilers---presumably VC++ under Windows, and g++ under Linux
or Unix. The answer, of course, is to write standard C++, and
to avoid the system specific API's, encapsulating them when you
must use them.
Then I'd use UnitTest++ to write lots of unit tests, and I'd
configure some scripts and Makefiles to compile and run all
the tests each time I changed the code.
That's a different problem. I certainly can't imagine anyone
writing makefiles which didn't run the unit tests automatically
before making the component visible to other components. But
how to do this is more a problem of how to write portable
makefiles. It's a problem which isn't really on topic here, but
I might add that I've yet to find a solution, other than
installing the same make (GNU make) everywhere.
I always configure these scripts to trigger automatically when
I save the files in my editor.
You mean you can't save partially edits? I tend to save any
time I've written two or three lines of code; long before I've
gotten anything which will compile. (Save early, save often, as
the man said.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34