Violin Iliev's blog and homepage

14Jun/082

Cross-compiling windows applications under Linux with Wine and DevC++

Cross-compileSince I'm trying to switch to Linux(Ubuntu) as my primary OS and since I had some stuff I really need to do under Linux, I had to find alternative applications for my activities. Well I don't play games much so this wasn't a big problem. I mainly do all stuff of programming and there are plenty of development tools for Linux. The big problem was a project I am working on witch is based on some Windows API calls. The IDE used for the project is DevC++. So I tried to install it under Linux and see if it could compile. I installed the last Wine version (1.0-rc5) and installed DevC++ under it. Everything went fine. I created a new empty console project and it compiled fine. However my project didn't compile at all :( . The IDE said that "windres.exe" failed with an strange error number. There was no way to make "windres.exe" work under WINE, so I decided to look for some alternative free Resource compiles. I came across GoRC by Jeremy Gordon. However it's command line arguments are different form windres' one so I had to write a wrapper. The wrapper takes the command line arguments that are passed to "windres" and then translates them and call GoRC. So I made a quick console project in DevC++(under wine) and created a simple wrapper. Then all I had to do is override the real "windres.exe". However things didn't went as expected. It turned out that "windres" produces COFF files which are then send to the linker but GoRC can only produce RES or OBJ files. I tried with the OBJ files but it was not the same COFF format. I was once again stuck. As I was searching for more info I found that "windres" can convert RES files into COFF files. I tried "windres" with a RES file and it successfully made a COFF file. It is not working well with RC->COFF, but it's working fine with RES->COFF. So I made some changes to the wrapper. It first creates a RES file with GoRC and then convert it to COFF using "windres". Guess what - IT IS WORKING!. I was able to compile my first Windows application with 2 RC files and everything went fine. However there are some problems. I tried another project and GoRC said that it could not find "windows.h" which is included in one of the RC files. So I had to copy that file to my project main directory and build went with no errors. The debugger is also working, with some problems, but it didn't worked well under windows either.
So finally I have a cross-compile environment and I can compile my applications for windows from Ubuntu :)
If you have the same problems you could try my wrapper and the GoRC utility. You can download them with the source of the wrapper(very mixed and non commented code :) ) here;
Just copy "windres.exe", "GoRc.exe" and "windres_real.exe" into your MinGW bin folder and override the files that exists. In my case the path is: "~/.wine/drive_c/Dev-Cpp/bin"