-
July 28th, 2009, 01:48 PM
#1
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.
-
July 28th, 2009, 01:52 PM
#2
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.
-
July 28th, 2009, 02:07 PM
#3
Re: Cross compatability with C++???
Originally Posted by Lindley
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. :-/
-
July 28th, 2009, 02:08 PM
#4
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.
-
July 28th, 2009, 02:12 PM
#5
Re: Cross compatability with C++???
Originally Posted by Lindley
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.
-
July 28th, 2009, 02:16 PM
#6
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.
-
July 28th, 2009, 03:41 PM
#7
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).
-
July 28th, 2009, 03:58 PM
#8
Re: Cross compatability with C++???
Originally Posted by David2010
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.
-
July 28th, 2009, 04:29 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|