crossing between Linux and Windows and Mac

Hi,
I have a very simple c++ code, and it is using all standard static libraries, which I believe are all defined on Unix/Linux and Windows.
I have developed my code on Lnix, and I've build an object file, which I can run easily on Linux.

My question is that is there a way for me to tell gcc, my Linux compiler, to be
able to produce an object file, that can be used on let's say a Windows machine? How about a Mac machine?
Or maybe there is a way, that I can specify in my source code, to know what the target operating system is?

please advise,
thanks,
RB
As long as you don't use a platform specific code, your application should run on either platform. For insance, if you code with Generic STL C++ using std::string, you can run cross platforms. But on the other hand, say you use MFC, CString which is windows dependent, then you can't run on Linux or Unix.
It is possible to set gcc up as a cross compiler, but very difficult to set up and link with the correct libraries. You would be far better to compile the code on the target system. gcc (from xcode) on Mac and Visual Studio on Windows.

Like the above posters says, as long as you use platform independent stuff, then you should be able to compile on Win/Mac/Linux no problem.

thanks for the replies,

In fact, I have a VERY simple C++ program, it is probably not even more than 30 lines of code, and all it is doing it is mostly dealing with File IO's. I will be honest, and the only library that I included is something called boost::filesystem, but I did search and found out that the "boost" library should run on all platforms. Granted that if this is true, is there a simple way for me to cross platforms.
As I said, I don't have anything fancy, it is just simple c++ code, with opening files, and reading files, and maybe renaming some files, and that is about it. It is a command line C++ code, and doesn't involve any fancy GUI's.
I developed this C++ code on a linux machine, with the following version info:
Linux 2.6.18-164.el5 x86_64
And, I have access to most of gcc versions (4.3.5, 4.4.0, 4.5.1, 4.5.2, 4.6.0)

And, all I want to do is to bring this code over to my classic Mac:
Mac OS leopard 10.6

I tried to read more about this, and I came across the following link:
http://www.sandroid.org/imcross/

This looks very complicated, and just to do that it will take me days, to get it going, and plus I would need a huge storage place on my disk to install all these packages.

I am really hoping there should be a way to bring my simple code over from Linux to Mac, without going through all these massive steps listed above.

my c++ code, has only one function() and then the main().
My guess would be that there should be way simpler method of doing this, since my code is fairly simple.

I really appreciate some help.

thanks,
RB

As kev82 stated, without using a cross-platform compiler, you would have to compile the code on each target machine.

i.e.
1. Compile code as you have done on Linux using gcc
2. Copy your code onto a Mac system and be sure to acquire the OS X version of the boost library. Compile your code there (I haven't programmed on Mac but it seems XCode is the compiler of choice).
3. Copy your code onto a Windows system and be sure to acquire the Windows version of the boost library. Compile your code there (using, e.g. Visual Studio)

After this, you should have three separate executables (one for each OS). It seems you have taken care to use platform-independent code, which is good, so you hopefully won't have to change your code for each compilation.
Topic archived. No new replies allowed.