View previous topic :: View next topic |
Author |
Message |
PrakashP Veteran
Joined: 27 Oct 2003 Posts: 1249 Location: C.C.A.A., Germania
|
Posted: Tue Feb 08, 2005 2:16 pm Post subject: HOWTO: Cross-compiling for Windows with KDevelop and MinGW |
|
|
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 |
|
|
-Rick- Tux's lil' helper
Joined: 29 Aug 2004 Posts: 77 Location: Holland
|
|
Back to top |
|
|
CybeRDukE Tux's lil' helper
Joined: 16 Jul 2002 Posts: 92
|
Posted: Thu Feb 10, 2005 9:31 pm Post subject: |
|
|
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 https://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 |
|
|
PrakashP Veteran
Joined: 27 Oct 2003 Posts: 1249 Location: C.C.A.A., Germania
|
Posted: Thu Feb 10, 2005 9:51 pm Post subject: |
|
|
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 |
|
|
suid77 Tux's lil' helper
Joined: 10 Dec 2003 Posts: 81 Location: Seattle
|
Posted: Tue Aug 02, 2005 8:20 pm Post subject: |
|
|
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 |
|
|
Colonel Paneek n00b
Joined: 06 Mar 2003 Posts: 42
|
Posted: Tue Aug 09, 2005 7:16 am Post subject: |
|
|
I just cross compiled my first wxWidgets app.
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 |
|
|
Colonel Paneek n00b
Joined: 06 Mar 2003 Posts: 42
|
Posted: Tue Aug 30, 2005 7:04 am Post subject: |
|
|
There is now an ebuild for the cross-compiled wxWindows 2.6.1. |
|
Back to top |
|
|
hvengel Guru
Joined: 19 Sep 2004 Posts: 515
|
Posted: Sat May 13, 2006 7:55 pm Post subject: |
|
|
Colonel Paneek wrote: | I just cross compiled my first wxWidgets app.
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 |
|
|
dingfelder Apprentice
Joined: 27 Jun 2007 Posts: 162 Location: New Zealand
|
Posted: Tue Jul 24, 2007 11:32 pm Post subject: |
|
|
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 |
|
|
|