Cross-Compiling from Linux

Hi to all,
I know that what I'm going to say is going to sound very strange to many of you, so I'll try to explain a bit... I made a Unix C Launcher for *nix systems some time ago. This launcher actually only starts the JVM using the Unix function execvp().
After some time I decided to build an equivalent launcher for Win32. The first thing I did was to install the MinGW over the Wine emulator and compile the sources using gcc over MinGW. The result is good, since it works well, runs smoothly and the application size increases not very much...
I like this result, but I would like to still improve it, building a Win32 executable that uses only native functions (i.e. the ones coming from the windows headers, like CreateProcess()). The problem is that I can't find a Win32 compiler (except gcc-MinGW) that will run over Wine... and I can't install Visual C++ (or any other compiler) on Windows since I removed Vista when I installed Linux.
So I'd like to know if someone of you already attempted this task successfully, the one of installing and running a Win32 compiler from Linux.

Thanks for your time and help
Marco
GCC can cross-compile, but not by default. You need to build a cross-compiler and environment.

Here are some useful pages I found
http://jrfonseca.dyndns.org/projects/gnu-win32/documentation/cross/
http://forums.codeblocks.org/index.php?topic=3343.0
http://www.torriefamily.org/~torriem/cross/

You'll also need the Windows include and runtime packages. That last link has very nice, explicit instructions about that.

Good luck and have fun!
Thanks for your help Duoas, you're always very fast with your replies, and you go straight to the problem at hand...
I studied all the links that you gave me, and I tried two of those.

The first one was the Code::blocks one: if someone of you is interested, it works pretty well and the tutorial is a good one, very simple and clear. But, unfortunately, the executable size just became 10 times bigger than the ones obtained from gcc-MinGW installed over Wine. I personally think that, if the price to pay to have a native function for Win32 is that of increasing so much the size, it is not worth. I actually expected a size growth compared to the Unix binary, but I didn't expect it to become greater than the executable obtained some days ago.

The second one is the last link you posted: again, the tutorial is good and goes straight to the problem. Again, the size of the executable is so much increased (though not as in the above case, here we talk something like 4 times the initial size obtained with MinGW). Again, I think that this excessive size increase contradicts the motivations that led me down this path.

Fact is, I think that, for now, I'll release the executable I obtained with gcc-MinGW without cross-compiling...
But, since I already tested those two methods, I can offer help and/or clarifications to everyone of you who is interested in using these tools for cross-compiling.

I have to say, as a final note, that setting these two cross-compilers was very funny indeed, and very educative.
you're always very fast with your replies

Just because I'm mindlessly checking in so often...

Windows MinGW binaries are by default very large. You should compile with the appropriate options or just run strip on the resulting EXE to cut down on unneeded stuff.

The other difference is that *nix environments default to dynamic linking (so you get nice, small ELFs, but they won't work on a system where someone is missing a needed SO). On Windows, it is more common to statically link, and GCC does just that by default. Again, you can change this with the appropriate compiler options to get smaller EXEs. And again, you have to make sure your target has the appropriate DLLs to run.

It is a tradeoff. Alas.
Last edited on
I know what you're saying Duoas, and I actually though of it yesterday while I was "playing" with the two cross-compilers. Fact is, I think that, to obtain the Win32 executable, I could spend a lot of time to find the "perfect options combination" for the cross-compiler using a native source code (which I haven't found), or I could just use the MinGW-Cygwin port of gcc for Win32 (installed over the Wine layer) to compile a *nix code.
I don't mind spending a lot of time finding the "perfect combination", it's just the fact that I have to provide the executable and the source code on Wednesday this week when I'm going to discuss the Theory of Computation exam. So, I just think that messing up with the options right now is not the wisest thing to do, since I have a pressing deadline and I need some time to look again at some arguments of the exam...

But, since I intend to release the source, I also intend to provide the community with a native code executable. I just can't do that well (and increasing the size of 10 times is definitely not my concept of doing things well) right now, since I'm actually out of time.

The cross-compilers that I have set up (and especially the MinGW) will be very useful to me in the near future.

Again, thank you for your help and your knowledge.
Last edited on
Topic archived. No new replies allowed.