CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2009
    Posts
    100

    Cross compatability with C++???

    Sorry if this has already been answered but if I make a C++ program in linux with GCC but only use the C++ libraries then will the executable work with linux and windows?

    I would think it would because its not tied to any OS.

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Cross compatability with C++???

    You can write cross-platform code fairly easily. However, the same executable can never be expected to work on multiple platforms----it may not even work between different versions of Linux.

    You'll need to re-compile the code on each platform you want it to run on.

  3. #3
    Join Date
    Jun 2009
    Posts
    100

    Re: Cross compatability with C++???

    Quote Originally Posted by Lindley View Post
    You can write cross-platform code fairly easily. However, the same executable can never be expected to work on multiple platforms----it may not even work between different versions of Linux.

    You'll need to re-compile the code on each platform you want it to run on.
    Darn because I don't have a copy of windows anymore. :-/

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Cross compatability with C++???

    It may be possible to build for a target platform on a different platform.

    I'm not positive how feasible that is, but it's a possibility.

  5. #5
    Join Date
    Jun 2009
    Posts
    100

    Re: Cross compatability with C++???

    Quote Originally Posted by Lindley View Post
    It may be possible to build for a target platform on a different platform.

    I'm not positive how feasible that is, but it's a possibility.
    How exactly would I accomplish this? I am stumped. lol

    I was told that if I JUST used the C++ libraries and didn't use anything permanently linked to windows or linux then it would work on both.

  6. #6
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Cross compatability with C++???

    The same source code will work on both. Compilers exist specifically because machine code is so much more architecture-specific than source.

  7. #7
    Join Date
    Nov 2006
    Posts
    1,611

    Re: Cross compatability with C++???

    I was told that if I JUST used the C++ libraries and didn't use anything permanently linked to windows or linux then it would work on both.
    Either you misunderstood, or the information was false.

    An operating system provides an interface to your application, which is "wired" to you through the runtime library. The format of the executable file for any operating system is unique to its design. This is why you can't run 64 bit executables in a 32 bit system, even if the CPU supports 64 bits, and even with both of these targets were Windows (or Linux).

    There is a very intricate set of interfaces between your code and the operating system that simply must match, rather exactly, or it can't execute.

    You must generate new compilations for each target.

    Java, or other runtime oriented languages, are the only ones that can actually run on different operating systems from the same "executable" file.
    If my post was interesting or helpful, perhaps you would consider clicking the 'rate this post' to let me know (middle icon of the group in the upper right of the post).

  8. #8
    Join Date
    Aug 2007
    Posts
    858

    Re: Cross compatability with C++???

    Quote Originally Posted by David2010 View Post
    Darn because I don't have a copy of windows anymore. :-/
    Even if you can compile windows executables on linux, there wouldn't be much point. Pretty much the only programs that you can expect to directly port from one platform to another are relatively simple apps that use only ANSI C++ (and perhaps Boost). As soon as you start dealing with platform specific stuff -GUI, graphics, networking, all of that kind of thing- you can't realistically develop for a platform that you don't have available for testing or debugging.

  9. #9
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Cross compatability with C++???

    Yeah, just make the code] cross platform. You need to recompile it for each platform. Platforms can't run each other's programs. You may need some specialized code for each platform, but that can be handled with preprocessor.

    I have an enormous program that runs on Solaris, Windows, OSX, and Linux with the same code, it's not hard if you know what you're doing. I use wxWidgets for interfacing with the GUI and the OS. I have some preprocessor to switch between 32 and 64 bit windows versions, and extensions and such.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured