C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to write C++ code that compiles in Windows/Linux

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
silviu
Guest





PostPosted: Wed Oct 29, 2003 6:02 pm    Post subject: How to write C++ code that compiles in Windows/Linux Reply with quote



Hi All,

I have to write C++ code (server code) that will compile/run on both
Windwos and Linux OS's.

Could someone give me some pointers to info on this matter.

Thanks in advance for your help.

Silviu
Back to top
Victor Bazarov
Guest





PostPosted: Wed Oct 29, 2003 7:03 pm    Post subject: Re: How to write C++ code that compiles in Windows/Linux Reply with quote



"silviu" <thelinuxguy1997 (AT) yahoo (DOT) com> wrote...
Quote:
I have to write C++ code (server code) that will compile/run on both
Windwos and Linux OS's.

Could someone give me some pointers to info on this matter.

The simplest solution is to use only standard mechanisms and classes.
Given that you have a standard-compliant compiler on each platform,
programs will be source-code compatible and should have the same
side effects (behaviour).

Victor



Back to top
Howard
Guest





PostPosted: Wed Oct 29, 2003 7:05 pm    Post subject: Re: How to write C++ code that compiles in Windows/Linux Reply with quote




"silviu" <thelinuxguy1997 (AT) yahoo (DOT) com> wrote

Quote:
Hi All,

I have to write C++ code (server code) that will compile/run on both
Windwos and Linux OS's.

Could someone give me some pointers to info on this matter.

Thanks in advance for your help.

Silviu

Simple. Don't write any platform-specific code! :-)

Seriously, though...do you have to provide a GUI? Handle files/directories?
Databases? Manage system resources? If yes, then you'll need at least
*some* code that is platform-dependant, which means it will be written
differently on each platform you target. Depending on your needs, there is
third-party, cross-platform software out there. Some SDK's are writtin with
this in mind, so that most porting work is simply a matter of setting up
your projects differently. You also have to deal with what compiler(s)
you'l be using, and that may change how you do some things.

If you don't have to worry about those things, then simply write your code
such that it follows the C++ standard (as discussed here), and avoid any
platform-specific junk (like MFC in VC++ apps.)

Check Google for cross-platform software if you need it.

Best of luck!
-Howard



Back to top
John Gabriele
Guest





PostPosted: Wed Oct 29, 2003 10:18 pm    Post subject: Re: How to write C++ code that compiles in Windows/Linux Reply with quote

silviu wrote:
Quote:
Hi All,

I have to write C++ code (server code) that will compile/run on both
Windwos and Linux OS's.

Could someone give me some pointers to info on this matter.

Thanks in advance for your help.

Silviu


If you must use platform-specific code to handle the sort of stuff
Howard mentioned, do your best to compartmentalize that code away
from the rest of your program's logic.


--
--- remove zees if contacting via email ---


Back to top
Sandeep
Guest





PostPosted: Thu Oct 30, 2003 3:08 am    Post subject: Re: How to write C++ code that compiles in Windows/Linux Reply with quote

Just regular C++ should work on both platforms. Just be
careful about the case insensitivity of the Windows file system.

If you are planning to write GUI code, the best option is
wxWindows (www.wxwindows.org)

Sandeep
--
http://www.EventHelix.com/EventStudio
EventStudio 2.0 - System Architecture Design CASE Tool
Back to top
Medi Montaseri
Guest





PostPosted: Thu Oct 30, 2003 6:07 am    Post subject: Re: How to write C++ code that compiles in Windows/Linux Reply with quote

[email]thelinuxguy1997 (AT) yahoo (DOT) com[/email] (silviu) wrote in message news:<f53c2ba1.0310291002.2f266beb (AT) posting (DOT) google.com>...
Quote:
Hi All,

I have to write C++ code (server code) that will compile/run on both
Windwos and Linux OS's.

Could someone give me some pointers to info on this matter.

Thanks in advance for your help.

Silviu

I'd also recommend:

1- Layer your code so that you'll tuck all the OS specfic code in that
class, perhaps
an OSIL (OS Independent Layer) on top of OS1, OS2, ...., etc.

2- Use a common compiler if possible. For example if you will be using
GCC on Linux,
see if you can use the same GCC for your Windows. This way you let the
compiler and glibc++
authors figure out the differences and you stay out of that game.

3- If you must use Microsoft VC++, use their latest 7.x as 6.x does
not have all the STL
or their implementation might differ a bit.

4- If you use fancy C++ features, you might run into some issues; For
example RTTI is
definitly different in GCC and VC++.

5- If you ever plan to port to 64 bit, whach out as Microsoft is not
up to speed on that
for example in VC 64 bit, a long is still a 32 bit.

6- Work with iostream an not printf stuff as their format specs are
different.

If you use GCC on both, you don't have to worry about many of above
stuff

Now if you use Win32 API, you'll find that Microsoft has so many
Helper Functions
that you'll be both confused and for ever hooked on their products....

Just use plain o-C++

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.