views:

2346

answers:

5

Just that. I would like some information (links, reference, examples...) to guide me to do that.

I don't even know if it's possible.

My objective is to compile a program in Linux and get a .exe file that I can run under windows.

+1  A: 

The Cygwin project does exactly this.

Jason Cohen
Erm... no it doesn't. That is a Linux-like environment that runs on Windows.
rq
Which should be able to compile the same source as Linux. But, as you say, that's not cross-compiling.
paxdiablo
+11  A: 

The basics are not too difficult:

sudo apt-get install mingw32    
cat > main.c <<EOF
int main()
{
  printf("Hello, World!");
}
EOF
i586-mingw32msvc-cc main.c -o hello

Replacing apt-get for yum, or whatever your Linux distro uses. That will generate a hello.exe for Windows.

Once you get your head around that, you could use autotools, and set CC=i586-mingw32msvc-cc

CC=i586-mingw32msvc-cc ./configure && make

Or use CMake and a toolchain file to manage the build. More difficult still is adding native cross libraries. Usually they are stored in /usr/cross/i586-mingw32msvc/{include,lib} and you would need to add those paths in separately in the configure step of the build process.

rq
One thing to note with this is that some libraries don't like to cross-compile. If your only choices are an .exe installer and source, you may want to install the library under wine and then copy the libraries and headers into your mingw search path. I never could get Boost to cross-compile
Branan
Would you mind guide me to how can I test such compiled program with Wine?
NawaMan
`wine hello.exe` should do it!
rq
+2  A: 

It depends on what you mean (I couldn't really say).

  1. If you mean that you want to use an existing Linux application on Windows, then you could try compiling it using cygwin on Windows. This however does not give you a Windows executable free from all dependencies towards cygwin (your executable still depends on the cygwin.dll) - and it still may need some porting before it will work. See http://www.cygwin.com

  2. If you mean that you want to be able to perform the actual compilation of a Windows application on Linux and produce a .exe file that is executable on Windows - thus using your Linux box for development and/or compilation then you should look into MinGW for Linux which is a tool for crosscompiling for Windows on Linux. See http://www.mingw.org/wiki/LinuxCrossMinGW

Best regards!

Subtwo
A: 

Thanks for the help!

dfdf
A: 

I suggest you give the following, GUB (Grand Unified Builder) a try as it cross-compiles several packages with their dependencies and assembles them into a single installation package for currently 11 architectures. You can download a prebuilt iso for installation in a VM from here and follow the source here. It can currently be used to cross-compile GNU LilyPond/ GNU Denemo / Inkscape and OpenOffice.org.

The target architectures are:

  • darwin-ppc - tar.bz2 file for Darwin 7 (MacOS 10.3)/PowerPC
  • darwin-x86 - tar.bz2 file for Darwin 8 (MacOS 10.4)/x86
  • mingw - mingw executable for Windows32
  • linux-x86 - shar archive for Linux/x86
  • linux-64 - shar archive for Linux/x86_64
  • linux-ppc - shar archive for Linux/PowerPC
  • freebsd-x86 - shar archive for FreeBSD 4/x86
  • freebsd-64 - shar archive for FreeBSD 6/x86_64
  • cygwin - .tar.bz2 packages for Cygwin/Windows32
  • arm - shar archive for Linux/ARM (largely untested)
  • debian - shar archive for Debian (largely untested)
1.01pm