 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
silviu Guest
|
Posted: Wed Oct 29, 2003 4:41 pm Post subject: How can I write C++ code for Windows/Linux |
|
|
Hi All,
I have to write C++ code that can be compiled (and run) on both
Windows and Linux/Unix OS's.
Could someone give me hints, links, info on this matter?
Thanks in advance for any help.
Silviu
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Thomas Mooney Guest
|
Posted: Thu Oct 30, 2003 5:34 am Post subject: Re: How can I write C++ code for Windows/Linux |
|
|
silviu <thelinuxguy1997 (AT) yahoo (DOT) com> wrote
| Quote: | Hi All,
I have to write C++ code that can be compiled (and run) on both
Windows and Linux/Unix OS's.
Could someone give me hints, links, info on this matter?
Thanks in advance for any help.
Silviu
|
Perhaps this would be helpful:
www.wxwindows.org
--
TFM3
Note: Spam-resistant e-mail address
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ben Hutchings Guest
|
Posted: Thu Oct 30, 2003 5:40 am Post subject: Re: How can I write C++ code for Windows/Linux |
|
|
In article <f53c2ba1.0310281425.755cc01 (AT) posting (DOT) google.com>,
silviu wrote:
| Quote: | Hi All,
I have to write C++ code that can be compiled (and run) on both
Windows and Linux/Unix OS's.
Could someone give me hints, links, info on this matter?
|
The simplest way to do this is just to write portable code -
don't assume anything about implementation-defined, unspecified
or undefined behaviour and don't use any functions or classes
outside the standard library.
Also, if you can, avoid using old compilers that don't support
the standard well, e.g. g++ versions before 3.2 and VC++ before
7.0. Not only do these not provide all the standard language
and library features, they provide non-standard extensions that
you might find yourself using by accident.
In practice most application require functionality beyond what
the standard defines. Even if that functionality exists in most
operating systems, the APIs to it differ. This means that the
application must use different code when built under different
implementations. There are several ways to do this, including:
1. Put implementation-specific code within #if...#endif blocks
where the #if directive tests a macro or macros that are
pre-defined under particular implementations, e.g. _WIN32
for Windows-specific code.
2. Put implementation-specific code in separate files. Select
between these in the makefile or similar file controlling
the build process.
3. Use a third-party library which has already been ported to
the implementations you want to use.
For example, the standard says nothing about directories,
though most filing systems support them. On Windows you must
use CreateDirectory to create a directory and if it fails use
GetLastError to find out what went wrong. On Unix you must
use mkdir and then check errno. Of course the error codes are
different too - so it's a lot of work to produce a common
interface. In this case one can use the Boost.Filesystem
library <http://www.boost.org/filesystem/>, which provides a
common interface to Win32 and POSIX file-systems (and
potentially others).
There are too many differences between Windows and Unix APIs
for me to enumerate them, so I shan't attempt to. I can only
suggest some libraries to investigate:
- ACE <http://www.cs.wustl.edu/~schmidt/ACE.html>
- Boost <http://www.boost.org/>
- gtkmm <http://www.gtkmm.org/>
- wxWindows <http://www.wxwindows.org/>
There's a longer list at
<http://vipe.technion.ac.il/~shlomif/abstraction/>.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Michael J. Reeves, AA, AS Guest
|
Posted: Thu Oct 30, 2003 3:23 pm Post subject: Re: How can I write C++ code for Windows/Linux |
|
|
On 29 Oct 2003 11:41:00 -0500, [email]thelinuxguy1997 (AT) yahoo (DOT) com[/email] (silviu) wrote:
| Quote: | Hi All,
I have to write C++ code that can be compiled (and run) on both
Windows and Linux/Unix OS's.
Could someone give me hints, links, info on this matter?
Thanks in advance for any help.
|
A key issue is PORTABILITY.
To ensure portability, you must use a library that is common to
ALL ISO/ANSI compilers.
Typically, this is the Standard Template Library (STL ).
Check out the references and links at:
http://www.cs.rpi.edu/projects/STL/htdocs/stl.html
IMHO...
MJR
(REMOVE "NoSPAM." from REPLY address to reply)
(This email scanned by Norton Anti-Virus and Certified VIRUS FREE!)
Michael J. Reeves, AA, ASc
E-Mail: [email]michaeljreeves (AT) comcast (DOT) net[/email]
---------------------------------------------------------
I have no SPAM. I don't give a SPAM.
I take no SPAM from anyone. I am NOT in the SPAM business!!!
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ben Hutchings Guest
|
Posted: Fri Oct 31, 2003 2:46 am Post subject: Re: How can I write C++ code for Windows/Linux |
|
|
Michael J. Reeves, AA, ASc wrote:
| Quote: | On 29 Oct 2003 11:41:00 -0500, [email]thelinuxguy1997 (AT) yahoo (DOT) com[/email] (silviu) wrote:
Hi All,
I have to write C++ code that can be compiled (and run) on both
Windows and Linux/Unix OS's.
Could someone give me hints, links, info on this matter?
Thanks in advance for any help.
A key issue is PORTABILITY.
To ensure portability, you must use a library that is common to
ALL ISO/ANSI compilers.
Typically, this is the Standard Template Library (STL ).
|
The STL is not the same thing as the standard C++ library, though
they overlap.
No, that predates the changes that were made to the STL in the
course of standardisation.
Dinkumware's C++ library reference
<http://www.dinkumware.com/refxcpp.html> is a much better
reference and covers the whole standard library.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
kalev- Guest
|
Posted: Fri Oct 31, 2003 2:51 am Post subject: Re: How can I write C++ code for Windows/Linux |
|
|
Thomas Mooney wrote:
| Quote: | silviu <thelinuxguy1997 (AT) yahoo (DOT) com> wrote in message
news:f53c2ba1.0310281425.755cc01 (AT) posting (DOT) google.com...
Hi All,
I have to write C++ code that can be compiled (and run) on both
Windows and Linux/Unix OS's.
Could someone give me hints, links, info on this matter?
Thanks in advance for any help.
Silviu
Perhaps this would be helpful:
www.wxwindows.org
|
I think "Qt" ()is worthwhile to meantion as a GUI-toolkit as well..
http://www.trolltech.no
jk
--
Every day above ground is a good day
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
R.F. Pels Guest
|
Posted: Sun Nov 02, 2003 12:05 pm Post subject: Re: How can I write C++ code for Windows/Linux |
|
|
silviu wrote:
| Quote: | I have to write C++ code that can be compiled (and run) on both
Windows and Linux/Unix OS's.
|
Just some thoughts:
#1: Rigorously factor out platform specific stuff from your program,
most notable, GUI and IO stuff.
#2: Proper design is important here.
#3: Try to find two compiler versions that are roughly comparable
in terms of standards compliance and/or bugs.
#4: If you're using STL, find an STL implementation that behaves
similar for both platforms. On a more general note that advice
goes for any thirdparty product used in the application
#5: Start with the platform that has the least features, i.e.,
start on the UNIX side and then move to the Windows side.
--
Ruurd
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ed Avis Guest
|
Posted: Sun Nov 02, 2003 5:15 pm Post subject: Re: How can I write C++ code for Windows/Linux |
|
|
"R.F. Pels" <spamtrap (AT) tiscali (DOT) nl> writes:
| Quote: | #3: Try to find two compiler versions that are roughly comparable
in terms of standards compliance and/or bugs.
#4: If you're using STL, find an STL implementation that behaves
similar for both platforms.
|
You can use gcc and its bundled STL implementation on both platforms.
--
Ed Avis <ed (AT) membled (DOT) com>
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
kanze@gabi-soft.fr Guest
|
Posted: Tue Nov 04, 2003 7:30 pm Post subject: Re: How can I write C++ code for Windows/Linux |
|
|
"Michael J. Reeves, AA, ASc" <michaeljreeves (AT) comcast (DOT) net> wrote in
message news:<t9b0qvgotdfmban9cvubertrhu3nak7t19 (AT) 4ax (DOT) com>...
| Quote: | On 29 Oct 2003 11:41:00 -0500, [email]thelinuxguy1997 (AT) yahoo (DOT) com[/email] (silviu) wrote:
I have to write C++ code that can be compiled (and run) on both
Windows and Linux/Unix OS's.
Could someone give me hints, links, info on this matter?
Thanks in advance for any help.
A key issue is PORTABILITY.
To ensure portability, you must use a library that is common to ALL
ISO/ANSI compilers.
|
That is only a valid option if you actually have ISO conformant
compilers on all platforms.
The simplest solution, of course, IS to use the same compiler (and
library) on all platforms. Comeau/Dimkumware is doubtlessly the most
compliant, and is available on a very wide range of platforms. G++
2.95.[23] is also very robust, albeit fairly old, and available on just
about anything.
Regretfully, you don't always have this luxury. There may be technical
reasons (you must link with third party libraries which are only
available for VC++ under Windows, etc.), or there may be political ones.
Finally, none of this addresses anything you might want to do that isn't
covered by the standard, such as threading (forget g++), GUI (third
partly libraries may impose a specific compiler), communications, etc.
--
James Kanze GABI Software mailto:kanze (AT) gabi-soft (DOT) fr
Conseils en informatique orientée objet/ http://www.gabi-soft.fr
Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France, +33 (0)1 30 23 45 16
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|