User forums > Using Code::Blocks

Howto - Cross Compiling in Linux using MingW32

(1/24) > >>

Hey everyone! Today I managed to finish figuring out how to set up the build options for cross compiling, debugging and running windows executables for projects built with codeblocks using linux... As such, I decided it was time to sign up for the c::b forums and post a howto in case anyone else was interested in knowing what I did...

The following is how I did this on Ubuntu 'Dapper Drake' Linux:

Step 1:

Install MingW32 for linux

--- Code: ---# sudo apt-get install mingw32

--- End code ---

Step 2:

Settings->Compiler and debugger settings

--- Code: --- Select GNU GCC Compiler and click the Copy button.
 Name this: MingW32 Compiler

--- End code ---

Step 3:

Click the Compiler tab and then click the #defines tab.
 Add the following:

--- Code: ---  WINVER=0x0400

--- End code ---

Click the Linker tab and the following under "Other Linker Options":

--- Code: ----lstdc++

--- End code ---
*Note: Not all of these are REQUIRED... As I have been recently messing with compiling apps for windows with ogl and dx9 support I have realized that there are some additions I have needed to add here... I will update accordingly when I know more.

Step 4:

Click the Directories tab and the Compiler tab.

--- Code: --- Modify the path to read the following (where ix86 is your architecture type):

--- End code ---

Click the Directories tab and the Linker tab:

--- Code: --- Modify the path to read the following (where ix86 is your architecture type):

--- End code ---

Click the Directories tab and the Resource Compiler tab:

--- Code: --- Modify the path to read the following (where ix86 is your architecture type):

--- End code ---

Step 5:

Click the Programs tab:

--- Code: --- C compiler: i586-mingw32msvc-gcc
 C++ compiler: i586-mingw32msvc-g++
 Linker for dynamic libs: i586-mingw32msvc-g++
 Linker for static libs: i586-mingw32msvc-ar
 Debugger: i586-mingw32msvc-gdb    **** MORE ON THIS LATER ****

--- End code ---

Click OK and save your changes.

Step 6:

Ubuntu's mingw32 package and from what I can tell, MingW32 in general doesnt really have a solid gdb option for debugging natively in linux so we're going to work around this using wine and mingw32's latest insight build for windows

Install Wine

--- Code: ---# sudo apt-get install wine

--- End code ---

Step 7:

Download Insight here:

--- Code: ---

--- End code ---

Step 8:

Once you download insight.exe, extract the archive using wine:

--- Code: ---wine insight.exe

--- End code ---
I extracted this to my desktop

Step 9:

Move the insight folder to /opt

the path should now look like

--- Code: ---/opt/insight/bin/gdb.exe
--- End code ---

Step 10:

create a shell script in /usr/bin:

(note: shell scripts should start with a hash (#) bang (!), ie: "# ! / bin / sh " [with no spaces] but when I add that the forum post tanks)

--- Code: ---# sudo gedit /usr/bin/i586-mingw32msvc-gdb

--- End code ---
and add the following:

--- Code: ---wine /opt/insight/bin/gdb.exe "$@"

--- End code ---

Save the file and quit gedit

Step 11:

--- Code: ---# sudo chmod +x /usr/bin/i586-mingw32msvc-gdb

--- End code ---
Now we have a way to execute the windows version of mingw32's gdb for windows in linux using our shell script wrapper

Step 12:

Create a new console application project in Codeblocks...

Using the wizard select the MingW32 Compiler option.

Step 13:

Right click the project and go to properties. Click the Targets tab and set the Output Filename to be whatever you want with a .exe file extension. Make sure the Type is a Console Application.

Step 14:

When I reached this step, compiled and tried to run my application I realized that for some reason codeblocks was trying to execute my .exe through /usr/bin/wine-auto (which I do not have)... So I created a simlink to wine:

--- Code: ---# sudo ln -s /usr/bin/wine /usr/bin/wine-auto

--- End code ---

Step 15:

Hit F9 in codeblocks and the hello world application runs!! YAY!

Set a breakpoint on line 5 and hit F8 and the application breaks in the debugger!! Woot!

Now you can successfully compile, execute, and debug windows applications in linux using codeblocks!!!

While this worked perfectly for me on my set up please try this yourself and let me know if I can update this howto in any way.

A special thanks to all the codeblocks developers... Code::Blocks is the most awesome IDE for linux I've ever used.

*Update: Added note about libraries

Impressive and detailed HOWTO! Thanks :)


--- Quote ---  __WIN95__
--- End quote ---

Is this needed for every windows version (say win XP sp2) ??

Well, I'd say this should definitely go into the WiKi. Great article!
If there are no objections, visualphoenix: Would you do that?
With regards, Morten.


Interesting really :). Good job.

Anyway, there was also my lost post... :)

Best wishes,


[0] Message Index

[#] Next page

Go to full version