Thread: Cross-platform code...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    4

    Cross-platform code...

    Hi

    I need your advice on the most suitable IDE/compiler for creating cross-platform programs, by that I mean so that I can compile the source code for a program to run on Linux, and also compile the same source for it to run on Windows.

    Thank you.

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    Its not so much your compiler as its the code you write. As long as you write code that is standards complient you should be able to port it to any OS
    Last edited by prog-bman; 06-18-2004 at 12:19 AM.
    Woop?

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    4
    Even so, which IDE guides you to make your code more portable? I heard and read around that, for example, Visual C++ from Microsoft don't really cater for portable code, but it seems to be Borland IDEs do. What do you think?

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    I would say go with Dev-C++ it uses MinGW a windows port of of GCC which is a very standards compatble compiler plus its free
    Woop?

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    If you always start with empty projects, I see no problems with VC++ and xp-code.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Jun 2004
    Posts
    4
    Thanks guys - just one last question, how does the Borland IDE compare to the Visual Studio IDE, generally? Which one do you use? Thanks again.

  7. #7
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    I personally havn't used borland or MS but i like dev. It's very user friendly plus if your just starting its free.
    Here's a link:
    www.bloodshed.net
    Woop?

  8. #8
    Registered User
    Join Date
    Jun 2004
    Posts
    4
    Thanks - I'll check it out. I've coded in c++ before, but I'm a bit rusty since I haven't done so in a while.

    I googled a bit and found the following information helpful:

    http://www.mozilla.org/hacking/portable-cpp.html

    Just put it here in case someone has the same question as me.
    Last edited by Sul; 06-18-2004 at 09:18 AM.

  9. #9
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I use Dev-C++ as well. I've used the MS.NET compiler, and have a copy of the borland compiler, but haven't used it. I personally like dev ALOT more than MS, but MS kinda holds your hand through the process... either way, if you start out with a blank file/project (console app), you shouldn't have any problem porting your code unless you use non-standard headers...

    I would go for Dev-C++, because it uses a port of the same compiler used on *nix boxes, and follows standards closely... and it's free... and it's open-source... and it's constantly updated...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  10. #10
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    YOU NEED MULTIPLE COMPILERS
    Normally, you compile the code on the "target" machine. For example, you would use Dev-C++ to write your code, and compile to the Windows exe file. Then, you'd copy the source files to your linux machine, and compile it again with a linux compiler. Or if you have a dual-boot machine, you can boot to linux and recompile.

    There are cross-compilers that can compile for a different platform, but these are generally used when its not possible or practical to complie on the target platform. If you were writing code for an automobile cruise-control, you would compile on your PC (using a special compiler), and then download the machine code to the target system which is not running Windows and may not have an x86 compatable processor.

    ALMOST ALL REAL-WORLD PROGRAMS CONTAIN NON-STANDARD CODE
    You have probably noticed that most commercial programs are avaliable for only one platform. Often, when there is a Mac and a PC version, they will be released at different times and be at different version numbers. This is a clue to how difficult it is!

    There is no color, graphics, mouse, or sound in standard C++. All of this user-interface shtuff is system-specific. (There are cross-platform GUI libraries.)

    DON'T GET ME WRONG
    One of the things that makes C/C++ so useful and popular is the fact that there is a solid widely-accepted language standard. And, the language standard language does not require any particular hardware.

    If you are really good, you will write the "core" of your program in standard C++, and put all of the platform-specific code in separate modules.
    Last edited by DougDbug; 06-18-2004 at 06:48 PM.

  11. #11
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    If you are really worried about portability, then make sure that system-specific code is abstracted out. That is, wrap the system-specific code in an interface, so that only the particular implementation of your feature needs to be modified when you change platforms. Since you have a uniform interface, you won't need to change anything else.

    Additionally, trying to make use of cross-platform libraries when possible helps. For example, Qt is a cross-platform GUI library. These libraries, however, rely primarily on the method mentioned above: one interface, many implementations.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cross Platform Question
    By PreachA in forum Game Programming
    Replies: 4
    Last Post: 07-12-2006, 07:36 PM
  2. wxWidgets cross platform GUI problem
    By BobS0327 in forum Linux Programming
    Replies: 2
    Last Post: 05-31-2006, 06:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM