BEFORE: (1) Check http://www.annexia.org/fedora_mingw (2) Check http://homes.merjis.com/~rich/mingw/ (3) Check http://www.annexia.org/tmp/02-win-api.pdf (4) Log in to misawa.merjis.com ---------------------------------------------------------------------- /topic Using the Windows cross-compiler Morning/afternoon/evening Fedora users from around the world! I've got a short prepared talk about APIs and cross-compilers, followed by a practical demonstration which you can follow along with If you want to follow the practical demonstration, go here to see how to set it up (best to start now): http://annexia.org/tmp/setup.txt Short, general interest questions are welcome any time. If you have long, deep technical questions or you want to argue with me about "why are we helping Windows users" etc then please leave it til the end. /topic Using the Windows cross-compiler: API basics What is an API? A collection of functions that you can call. Linux has hundreds of APIs, some with thousands of functions. Examples: POSIX/C99/libc: fork, getenv, fopen, ctime, printf, ... Gtk+: gtk_button_new, gtk_object_ref, gdk_colormap_query_color, ... libcurl: curl_easy_init, curl_easy_perform, curl_formadd, ... openssl: SSL_CIPHER_get_version, SSL_CTX_sess_connect, ... Most real world programs call just a few functions from a small number of APIs. http://www.annexia.org/tmp/02-win-api.pdf Looking at the diagram above, I've tried to summarise a few of the APIs you'll find on Linux. Thanks to the huge efforts of many free software developers over many years, those APIs are also available on Windows. The one obvious exception is POSIX/libc. libc is so directly tied to specifics of how Unix works that it's hard to port it (that's what Cygwin emulates). But it turns out most programs don't make too many calls to libc directly. Mostly they call higher level APIs (Gtk, Qt). Portability libraries and higher level APIs can replace a lot of libc calls and make software easier to port. Examples: Gnulib, glib2, Qt, NSPR, APR, kdewin32, Boost, POCO /topic Using the Windows cross-compiler: Cross-compiler basics Cross-compilers are like ordinary compilers, but they generate code for another machine. A common example are cross-compilers that generate code for embedded machines (the embedded machine isn't "big enough" to run a compiler on its own). Terminology: Build: The machine on which we build the software. (Fedora) Host: The system where the software will run. (Windows) Target: (You don't need to worry about 'target'. Technically it's different from 'host', but the terms are often wrongly used interchangably.) We treat Windows as a strange embedded machine (!) /topic Using the Windows cross-compiler: Practical demonstration We're going to use some software which isn't _yet_ in Fedora. It should be by the time Fedora 11 is released. In the meantime you need to use our temporary repository for a couple of packages. So: (1) Create a file /etc/yum.repos.d/mingw.repo containing this: [mingw] name=Fedora Windows cross-compiler, libraries and tools baseurl=http://homes.merjis.com/~rich/mingw/fedora-10/x86_64/ enabled=1 gpgcheck=0 You may need to adjust the URL by looking here: http://homes.merjis.com/~rich/mingw/ (2) As root do: yum install mingw32-gcc mingw32-gtk2 mingw32-crossreport mingw32-nsiswrapper wine (This is probably the point where that stolen machine hosting our temporary repository falls over :-) (3) Configure Wine: http://fedoraproject.org/wiki/MinGW/Configure_wine While you're doing that, download the sources: http://www.annexia.org/_file/tictactoe-1.0.tar.gz and unpack them somewhere as a non-root, ordinary user. wget 'http://www.annexia.org/_file/tictactoe-1.0.tar.gz' zcat tictactoe-1.0.tar.gz | tar xvf - cd tictactoe-1.0 Once the 'yum' command has finished, you can compile simple test programs using the cross-compiler easily. For example: cat > test.c #include main () { printf ("hello, world!\n"); } (press Ctrl D) i686-pc-mingw32-gcc test.c -o test.exe file test.exe i686-pc-mingw32-nm test.exe i686-pc-mingw32-objdump -p test.exe ./test.exe wine test.exe (If you get an error about missing DLLs, read http://fedoraproject.org/wiki/MinGW/Configure_wine ) I guess you can see from that, commands are just the same but preceeded by 'i686-pc-mingw-'. Also if Wine is installed then it adds a special handler to the Linux kernel so you can just run Windows binaries. [Except when that doesn't work for reasons we don't fully understand -- but 'wine prog.exe' always works]. Back to the Tic-Tac-Toe example http://www.annexia.org/_file/tictactoe-1.0.tar.gz If you've downloaded and unpacked this example, and the 'yum install' has finished, then you should be ready to compile this program which comes from the Gtk tutorial. To compile for Linux, you do: ./configure make ./ttt (It's a really stupid demo, so don't even try to play the game :-) Cross-compiling for Windows is just as easy: make clean # cleans up the Linux binary mingw32-configure make ./ttt.exe If you try the menu Help -> About you should see the Windows look and feel. 'mingw32-configure' is just a wrapper around configure. It really does: ./configure --host=i686-pc-mingw32 plus a few other flags and environment variables. That worked for everyone? You can take the 'ttt.exe' binary but it won't run directly on Windows. The reason is that it needs all the Gtk DLLs and Gtk configuration files. But we provide a way to wrap that up easily. First, for reasons which are obscure / a bug, you will need to install that ttt.exe binary, so do this *as root*: make install Then (as non-root again): make installer.exe ls -l installer.exe That gives you a Windows installer that contains everything (program, dependent DLLs, configuration files, desktop icon, menu entry, uninstaller). You can copy that file onto a Windows box and run it. /topic Using the Windows cross-compiler: Crossreport A final point about porting your own programs. Use our 'mingw32-crossreport' tool to help you. You just run it on an existing Linux (C/C++) compiled program, and it will tell you where potential problems might arise. mingw32-crossreport /usr/bin/eog | less /topic Using the Windows cross-compiler: Future directions (Win64, Mac OS X ?) Future directions: We have a working Win64 cross-compiler thanks to the excellent work of the mingw-w64 upstream project. We haven't cross-compiled any libraries for Win64 yet, but it's something we're looking at for a future Fedora. We have a sort-of-working Darwin (Mac OS X) cross-compiler. There are various issues which I summarised here: https://www.redhat.com/archives/fedora-devel-list/2009-March/msg00397.html /topic Using the Windows cross-compiler: How to get involved We *always* need volunteers: - people who know about intimate details of compiling on Windows and OS X - Fedora packagers - Fedora reviewers - testers - developers who want to cross-compile their own apps - developers who want to maintain Win32 ports of their own libraries Web site: http://fedoraproject.org/wiki/MinGW Mailing list: https://admin.fedoraproject.org/mailman/listinfo/fedora-mingw IRC: #fedora-mingw on FreeNode Status: http://www.annexia.org/fedora_mingw Any questions?