views:

149

answers:

5

Hi,

I have the source code for some very simple command line programs. I was considering the option of compiling them on a Linux machine (they were deveoped here) so they can be used on Windows. If I am not wrong this is called Cross-compiling. I have never tried it, but reading yesterday some information, it seems to be kind of complicated or not successful. I would like to hear about your opinions, and how could I port a simple "hello world" program, which compiles on Linux with g++.

Thanks

+7  A: 

Look into mingw, a suite of tools for building Win32 applications in Linux. If the programs don't depend on any Linux-specific functionality not supported by mingw, you should be fine.

unwind
how can one download the whole migwin system for windows? from here I only see a list of the individual parts of mingw:http://sourceforge.net/projects/mingw/files/
Werner
problem solvedmy stupitdty as due to the fact that I accessed the website from a linux. from a windows machine you get directly the setup.exe installer
Werner
A: 

Yes. We are currently compiling a 250 kloc app, running Qt with daily builds. It's working prefectly everyday, although I've to admit it is not distributed outside the company, but only used internal. For official releases, Visual Studio is prefered.

Compiled using mingw standard packages on Debian.

Didier Trosset
+1  A: 

I cross-compile on a daily basis. But I don't set up cross-compilers on a daily basis. It can be tricky, but it's certainly possible.

Artelius
A: 

As long as you use standard C++ your code will be cross-platform. You can also use cross-platform libraries like STL, boost, Poco, Qt, etc...

Only when you start to use platform specific code you lose portability. For example including <windows.h> will make your code only compilable on Windows. (There are techniques around this like the #ifdef macro. This enables certain code portions only on one platform.)

So a simple hello world program should work on Linux, Mac, Windows or any other platform. You don't need anything special for this.

Note:
Some may mention Cygwin or mingw32. I'll briefly explain what they are:
Cygwin allows you to compile Linux applications using gcc/g++ on a Windows machine.
Mingw32 allows you to compile Windows applications using gcc/g++ on a Windows machine.

Edit:
If you want to setup a system for cross-compilation, then I recommend that you have a look at cmake.

StackedCrooked
+3  A: 

Note that cross-compilation is not the same thing as cross-platform. With cross compilation, you compile the code to a Windows executable on the Linux box, then transfer the executable to a Windows box. With cross-platform, you transfer the source code to the Windows box and compile to a Windows executable using a Windows compiler.

The former is quite difficult (but not impossible), the latter is very easy, using a compiler such as MinGW, a others have mentioned.

anon