Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
HOWTO: Cross-compiling for Windows with KDevelop and MinGW
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
PrakashP
Veteran
Veteran


Joined: 27 Oct 2003
Posts: 1246
Location: C.C.A.A., Germania

PostPosted: Tue Feb 08, 2005 2:16 pm    Post subject: HOWTO: Cross-compiling for Windows with KDevelop and MinGW Reply with quote

This Howto explain how you can develop and compile Win32 stuff und KDevelop using MinGW.

First emerge MinGW. Do this in this order:

dev-util/xmingw-binutils
dev-util/xmingw-gcc
dev-util/xmingw-w32api
dev-util/xmingw-runtime
dev-util/xmingw-gcc

Yes, you need to emerge the cross-compiler twice, else you only get a C compiler and no C++ compiler, which makes it harder to integrate into kdevelop.

Well, I guess you already have KDevelop emerged, then let's make your first Win32 project:

- Select a C++ Win32 GUI App Project.

Unfortunately this won't bring you far, as configure errors out, so we need to change configure options:

First, pass these arguments to configure:

Code:

--target=i386-mingw32msvc --host=i386-mingw32msvc --build=i386-linux


Then you need to update CC, CXX and LD settings to reflect the names of installed compiler:

Code:

CC to i386-mingw32msvc-gcc
CXX to i386-mingw32msvc-g++
LD to i386-mingw32msvc-ld


This should already be enough. If you get an error running automake and friend and the configure, try to do it step by step:

- menu: Run automake & friends
- in konsole: libtoolize -f
- menu: configure

This should now go through and you can compile the hello world code. But executing is still involves using the console, so we change this behaviour:

Go to runtime options:

- select custom dir and type in absolute path to your app, eg. /home/user/MyProjects/testapp/default/src/

- executable: /usr/bin/wine

- arguments: full path to exe-file, eg. /home/user/MyProjects/testapp/default/src/testapp.exe

Now you should be able to start the compiled programme comfortably via button.

A hint: If you do GUI stuff, you probably need to define -D"_WIN32_IE=0x0500" in configure settings, as otherwise eg UDM_SETRANGE32 (or alike) won't be available.

That's the basics. Now come some findings which gave me quite a headache:

How to automatically "compile" rc files and link them?

I assume you already created the rc file inside your project. Now some hand-editing is necessary. Open the Makefile.am belonging to the (sub-)project, where you inserted the rc file. Insert these lines into it (warning, the "big space" in last line is a mandatory tab!):

Code:

SUFFIXES = .rc
RES = i386-mingw32msvc-windres

.rc.o:
   $(RES) $(RESFLAGS) $(AM_RESFLAGS) -o $@ $<


You need to include these lines into every Makefile.am, which has a rc file to compile.

That should be it!

How to compile dlls?

Well, this is a bit tricky. Make a new (executable; don't know whether (libtool) library would be better) subproject in kdevelop. Now comes some hand-editing of Makefile.am again. Insert/replace:

Code:

LINK = i386-mingw32msvc-dllwrap --def @top_srcdir@/testdll/testdll.def --dllname=testdll.dll --driver-name=i386-mingw32msvc-gcc


If you don't have a .def file, leave out that parameter. I guess the options are pretty self-explained.

This will give you a beautiful dll. Apparently the run button won't work if your project only consists of this dll, so it is advised that your main target is an exe using this dll, so you can debug the dll easily.


So, these are my findings, which cost me quite some time to gather. Still it is not perfect, but already comfortable enough for me. I especially would like to know how to integrate the use of 386-mingw32msvc-strip to strip the binary, which would otherwise be very bloated.

Please let me know your suggestions for improvements!


Last edited by PrakashP on Tue Feb 08, 2005 9:35 pm; edited 1 time in total
Back to top
View user's profile Send private message
-Rick-
Tux's lil' helper
Tux's lil' helper


Joined: 29 Aug 2004
Posts: 77
Location: Holland

PostPosted: Tue Feb 08, 2005 9:25 pm    Post subject: Reply with quote

Very nice, especially the dll part :)
_________________
Cube bots
Nixstaller - Easy creatable installers for *nix
Back to top
View user's profile Send private message
CybeRDukE
Tux's lil' helper
Tux's lil' helper


Joined: 16 Jul 2002
Posts: 92

PostPosted: Thu Feb 10, 2005 9:31 pm    Post subject: Reply with quote

that's great, thx!

now i can compile windows applications from linux using autoconf and wxWidgets. that's awesome!

btw, you might want to take a look at http://bugs.gentoo.org/show_bug.cgi?id=46420. there you can find an ebuild for a cross-compiled wxWidgets.
if you're using this in combination with autoconf, just add
Code:
--with-wx-config=/opt/xmingw/wxWidgets/bin/wx-config

to the configure-parameters mentioned above (assuming that you're using the kdevelop wxGTK template).
Back to top
View user's profile Send private message
PrakashP
Veteran
Veteran


Joined: 27 Oct 2003
Posts: 1246
Location: C.C.A.A., Germania

PostPosted: Thu Feb 10, 2005 9:51 pm    Post subject: Reply with quote

Ah, nice, as in near future I need wxWidgets for windows and so you spare me finding that out on my own. :)
Back to top
View user's profile Send private message
suid77
Tux's lil' helper
Tux's lil' helper


Joined: 10 Dec 2003
Posts: 81
Location: Seattle

PostPosted: Tue Aug 02, 2005 8:20 pm    Post subject: Reply with quote

I followed these instructions but had to do 2 extra things to get it to work:

1. Added /opt/xmingw/bin to my path. Otherwise the i386-mingw32msvc-* cross-compilers were not found
2. In kdevelop -> automake manager -> subprojects 'options' -> includes tab -> add -I/opt/xmingw/i386-mingw32msvc/include to 'directories outside the project'

Perhaps there are more elegant solutions, but this got it working for me.
Back to top
View user's profile Send private message
Colonel Paneek
n00b
n00b


Joined: 06 Mar 2003
Posts: 42

PostPosted: Tue Aug 09, 2005 7:16 am    Post subject: Reply with quote

I just cross compiled my first wxWidgets app. :D

In addition to emerging the xmingw toolchain as described in the OP, I also emerged dev-libs/wx-xmingw. Then I downloaded wxAuto as my autogen configured test program. Here is the script I used to build the Makefile... (with thanks to Benjamin Block)

#!/bin/bash

I1=/opt/xmingw/wxWidgets/include
I2=/opt/xmingw/i386-mingw32msvc/include
I3=/opt/xmingw/wxWidgets/lib/wx/include/msw-2.4-i386-mingw32msvc

export PATH="/opt/xmingw/bin:/opt/xmingw/i386-mingw32msvc/bin:$PATH"
export CC="i386-mingw32msvc-gcc"
export CXX="i386-mingw32msvc-g++"

unset CFLAGS
unset CPPFLAGS
unset CXXFLAGS
unset LDFLAGS

export CFLAGS="-I${I1} -I${I2} -I${I3}"
export CXXFLAGS="-I${I1} -I${I2} -I${I3}"

M=i386-mingw32msvc

./autogen.sh
./configure --target=${M} --host=${M} --build=i386-linux --with-wx-config=/opt/xmingw/wxWidgets/bin/wx-config
Back to top
View user's profile Send private message
Colonel Paneek
n00b
n00b


Joined: 06 Mar 2003
Posts: 42

PostPosted: Tue Aug 30, 2005 7:04 am    Post subject: Reply with quote

There is now an ebuild for the cross-compiled wxWindows 2.6.1.
Back to top
View user's profile Send private message
hvengel
Guru
Guru


Joined: 19 Sep 2004
Posts: 515

PostPosted: Sat May 13, 2006 7:55 pm    Post subject: Reply with quote

Colonel Paneek wrote:
I just cross compiled my first wxWidgets app. :D

In addition to emerging the xmingw toolchain as described in the OP, I also emerged dev-libs/wx-xmingw. Then I downloaded wxAuto as my autogen configured test program. Here is the script I used to build the Makefile... (with thanks to Benjamin Block)

#!/bin/bash

I1=/opt/xmingw/wxWidgets/include
I2=/opt/xmingw/i386-mingw32msvc/include
I3=/opt/xmingw/wxWidgets/lib/wx/include/msw-2.4-i386-mingw32msvc

export PATH="/opt/xmingw/bin:/opt/xmingw/i386-mingw32msvc/bin:$PATH"
export CC="i386-mingw32msvc-gcc"
export CXX="i386-mingw32msvc-g++"

unset CFLAGS
unset CPPFLAGS
unset CXXFLAGS
unset LDFLAGS

export CFLAGS="-I${I1} -I${I2} -I${I3}"
export CXXFLAGS="-I${I1} -I${I2} -I${I3}"

M=i386-mingw32msvc

./autogen.sh
./configure --target=${M} --host=${M} --build=i386-linux --with-wx-config=/opt/xmingw/wxWidgets/bin/wx-config


I tried this same type of thing and for some reason none of the variables such as PATH or CFLAGS get exported. Not sure what I am doing wrong. I am trying to build a library (lcms-1.15). Here is my script:

Code:
#!/bin/bash
# set up environment for mingw

export CFLAGS="-I/opt/xmingw/i386-mingw32msvc/include"
export CXXFLAGS="-I/opt/xmingw/i386-mingw32msvc/include"

export PATH="/opt/mingw/bin:/opt/xmingw/i386-mingw32msvc/bin:$PATH"

export CC="i386-mingw32msvc-gcc"
export CXX="i386-mingw32msvc-g++"

M=i386-mingw32msvc

# ./autogen.sh
./configure --target=${M} --host=${M} --build=i386-linux


When I run this it appears to work. But make fails and it appears the Makefile has major problems. I tried basically the same thing with VIGRA and it seemed to work. I was missing some other things that it needed to link and it built everything and failed on the link step. Seems very hit and miss. Is there a guide or howto somewhere on using mingw as a cross compiler? Also I need to be able to use QT and have not been able to find much information about using mingw and QT in a cross compiled environment. Anyone have any ideas about where more information can be found?
Back to top
View user's profile Send private message
dingfelder
Apprentice
Apprentice


Joined: 27 Jun 2007
Posts: 162
Location: New Zealand

PostPosted: Tue Jul 24, 2007 11:32 pm    Post subject: Reply with quote

fyi: the mingw32 packages don't seem to be part of prtage any more.

you will need to emerge sys-devel/crossdev which now inclides it.

see http://gentoo-wiki.com/HOWTO_MinGW for info
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum