Tag Archives: c/c++

How to Cross Compiling with codeblocks using linux

The following is how I did this on Ubuntu ‘Precise Pangolin’ Linux:

Step 1:

Install MingW32 for linux

# sudo apt-get install mingw32

Step 2:

Settings->Compiler and debugger settings

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

Step 3:

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


Click the Linker tab and the following under “Other Linker Options”:


*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.

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

Click the Directories tab and the Linker tab:

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

Click the Directories tab and the Resource Compiler tab:

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

Step 5:

Click the Programs tab:

 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 ****

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


# sudo apt-get install wine

Step 7:

Download Insight here:



Step 8:

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

wine insight.exe

I extracted this to my desktop

Step 9:

Move the insight folder to /opt

the path should now look like


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)

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

and add the following:

wine /opt/insight/bin/gdb.exe "$@"

Save the file and quit gedit

Step 11:

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

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:

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!!!

Source post:  Click here