Author Topic: Howto - Cross Compiling in Linux using MingW32  (Read 185649 times)

Offline visualphoenix

  • Advanced newcomer
  • *
  • Posts: 10
Howto - Cross Compiling in Linux using MingW32
« on: June 16, 2006, 01:52:25 am »
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: [Select]
# sudo apt-get install mingw32

Step 2:

Settings->Compiler and debugger settings
Code: [Select]
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:
Code: [Select]
  WINVER=0x0400
  __WIN95__
  __GNUWIN32__
  STRICT
  HAVE_W32API_H
  __WXMSW__
  __WINDOWS__

Click the Linker tab and the following under "Other Linker Options":
Code: [Select]
-lstdc++
-lgcc
-lodbc32
-lwsock32
-lwinspool
-lwinmm
-lshell32
-lcomctl32
-lctl3d32
-lodbc32
-ladvapi32
-lodbc32
-lwsock32
-lopengl32
-lglu32
-lole32
-loleaut32
-luuid
*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: [Select]
Modify the path to read the following (where ix86 is your architecture type):
 /usr/i586-mingw32msvc/include

Click the Directories tab and the Linker tab:
Code: [Select]
Modify the path to read the following (where ix86 is your architecture type):
 /usr/i586-mingw32msvc/lib

Click the Directories tab and the Resource Compiler tab:
Code: [Select]
Modify the path to read the following (where ix86 is your architecture type):
 /usr/i586-mingw32msvc/include

Step 5:

Click the Programs tab:
Code: [Select]
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
Code: [Select]
# sudo apt-get install wine

Step 7:

Download Insight here:
Code: [Select]
http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=82725&release_id=371590

Step 8:

Once you download insight.exe, extract the archive using wine:
Code: [Select]
wine insight.exe
I extracted this to my desktop

Step 9:

Move the insight folder to /opt

the path should now look like
Code: [Select]
/opt/insight/bin/gdb.exe
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: [Select]
# sudo gedit /usr/bin/i586-mingw32msvc-gdb
and add the following:
Code: [Select]
wine /opt/insight/bin/gdb.exe "$@"

Save the file and quit gedit

Step 11:
Code: [Select]
# 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:

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: [Select]
# sudo ln -s /usr/bin/wine /usr/bin/wine-auto

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
« Last Edit: June 18, 2006, 11:50:01 pm by visualphoenix »

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4276
    • Code::Blocks IDE
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #1 on: June 16, 2006, 09:23:20 am »
Impressive and detailed HOWTO! Thanks :)
Be patient!
This bug will be fixed soon...

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 4828
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #2 on: June 16, 2006, 10:49:42 am »
Quote
  __WIN95__

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

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 8695
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #3 on: June 16, 2006, 11:20:18 am »
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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #4 on: June 16, 2006, 03:42:32 pm »
Hello,

Interesting really :). Good job.

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

http://forums.codeblocks.org/index.php?topic=2688.0

Best wishes,
Michael

Offline visualphoenix

  • Advanced newcomer
  • *
  • Posts: 10
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #5 on: June 16, 2006, 05:52:35 pm »
Hello,

Interesting really :). Good job.

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

http://forums.codeblocks.org/index.php?topic=2688.0

Best wishes,
Michael


Yea, I want to say thank you to you as well Michael for the links. When I was originally trying to figure out how to do this they provided a couple of clues.

Offline visualphoenix

  • Advanced newcomer
  • *
  • Posts: 10
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #6 on: June 16, 2006, 05:54:28 pm »
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.

Hey Morten, Thanks for the comment! I was thinking of adding it to the wiki rightoff under Cross_Compiling but I figured I'd test the waters here to find out how it was recieved. I'll go ahead and add it. Once again thanks to all the dev's for such a kickin' IDE.

Offline visualphoenix

  • Advanced newcomer
  • *
  • Posts: 10
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #7 on: June 16, 2006, 05:56:47 pm »
Quote
  __WIN95__

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

Possibly although YMMV. I will need more time to look into this.
« Last Edit: June 16, 2006, 06:03:12 pm by visualphoenix »

Offline uFo-Z

  • Newcomer
  • *
  • Posts: 3
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #8 on: June 25, 2006, 11:38:02 am »
well, i created also a howto for Cross Compiling. I did not know that this howto exists and maybe we could bring together what belongs togehter. it is not that detailed like yours, but there are some pictures we could use.


http://wiki.codeblocks.org/index.php?title=Code::Blocks_and_Cross_Compilers

I also planed, are let me better say thougt about to start with a Cross Compiler plugin for C::B. The idea is to make a tool wich would setup some Paths, and vars in the Compiler and Debugger Tab, and also could download precompiled developer libs like SDL, ncurses ... to use them with the Cross Compiler. Then everybody who wants create Win executable under Linux would have an easier way.
Let me know if there are interesstes for such a plugin.  Atm i have exams so  i would start in some weeks, and maybe somone else would/could help me a litle bit with that thing.
 
bye bye, and thank you for C::B
« Last Edit: June 25, 2006, 11:56:44 am by uFo-Z »

Offline tiger

  • Advanced newcomer
  • *
  • Posts: 11
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #9 on: November 07, 2006, 09:04:26 am »
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: [Select]
# sudo ln -s /usr/bin/wine /usr/bin/wine-auto

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

When pressing F9 I can't debug the program, I got this error:
Code: [Select]
run-detectors: unable to find an interpreter for /home...../hello.exe
I think this is the reason:
Code: [Select]
Settings->Environment->General settings->Terminal to launch console: xterm -T $TITLE -e
But I don't know how to make the debugger work.
?
« Last Edit: November 07, 2006, 09:11:50 am by tiger »

Offline visualphoenix

  • Advanced newcomer
  • *
  • Posts: 10
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #10 on: November 07, 2006, 07:09:39 pm »
I'll look into your problem tonight. It has been a while since I used this setup.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3939
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #11 on: November 07, 2006, 08:47:31 pm »
Talking of cross-compiling, wouldn't that possibly be a less painful way of building MinGW/gcc 4.x?

The MSYS way is so darn painful, it never works satisfactory, and it takes ages to even run ./configure in every subfolder, not even thinking about actually compiling anything.

Have you ever tried doing a cross-compile of MinGW?
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline visualphoenix

  • Advanced newcomer
  • *
  • Posts: 10
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #12 on: November 07, 2006, 10:46:16 pm »
ummm... the howto is a setup of how to use codeblocks to do a cross compile with mingw... hes only having problems running the program through wine and using the wine debugger with codeblocks.

Offline koen

  • Advanced newcomer
  • *
  • Posts: 13
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #13 on: November 18, 2006, 07:28:28 pm »
After installing MingW32, how do I proceed to install the required wxWidgets header files, so I can compile wxWidgets projects? I think I'm just a bit lost on where to put the files. Did anyone manage to do this and is he/she willing to share some information?

Thanks!

Offline Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 1990
Re: Howto - Cross Compiling in Linux using MingW32
« Reply #14 on: November 18, 2006, 07:35:30 pm »
After installing MingW32, how do I proceed to install the required wxWidgets header files, so I can compile wxWidgets projects? I think I'm just a bit lost on where to put the files. Did anyone manage to do this and is he/she willing to share some information?

Thanks!
   //-- Wiki Index
       CodeBlocks Wiki Index
   //-- Wiki Main Page
    CodeBlocks Wiki Main Page

Read Topic:
Installing Code::Blocks from source on Windows or Linux or Fedora or ....