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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • silviu

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

    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
  • Victor Bazarov

    #2
    Re: How to write C++ code that compiles in Windows/Linux

    "silviu" <thelinuxguy199 7@yahoo.com> wrote...[color=blue]
    > 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.[/color]

    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


    Comment

    • Howard

      #3
      Re: How to write C++ code that compiles in Windows/Linux


      "silviu" <thelinuxguy199 7@yahoo.com> wrote in message
      news:f53c2ba1.0 310291002.2f266 beb@posting.goo gle.com...[color=blue]
      > 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[/color]

      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


      Comment

      • John Gabriele

        #4
        Re: How to write C++ code that compiles in Windows/Linux

        silviu wrote:[color=blue]
        > 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[/color]


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


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

        Comment

        • Sandeep

          #5
          Re: How to write C++ code that compiles in Windows/Linux

          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
          --
          Sequence diagram based systems engineering and architecture design tool. Built in support for alternative scenarios and multi-tier architectures.

          EventStudio 2.0 - System Architecture Design CASE Tool

          Comment

          • Medi Montaseri

            #6
            Re: How to write C++ code that compiles in Windows/Linux

            thelinuxguy1997 @yahoo.com (silviu) wrote in message news:<f53c2ba1. 0310291002.2f26 6beb@posting.go ogle.com>...[color=blue]
            > 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[/color]

            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++

            Comment

            Working...