Loading
Home ›
Exploit mingw and wine for cross-platform portability testing
Nov 28, 2007 By Kristian Erik H...
I frequently need to write portable C code that runs on Linux, UNIX, and Windows. Sometimes it is beneficial to cross-compile from Linux for Windows during testing. Here is a very simple example that will get you hacking win32 code on Linux by utilizing mingw and wine :-)
khermans@khermans-laptop:~/projects$ aptitude search mingw
i mingw32 - Minimalist GNU win32 (cross) compiler
i mingw32-binutils - Minimalist GNU win32 (cross) binutils
i mingw32-runtime - Minimalist GNU win32 (cross) runtime
khermans@khermans-laptop:~/projects$ wine --version
wine-0.9.30
khermans@khermans-laptop:~/projects$ emacs -nw hello.c
khermans@khermans-laptop:~/projects$ cat hello.c
/*
* Author: Kristian Hermansen <kristian.hermansen@gmail.com>
* For demonstration purposes of cross-compilation...
*/
/* general includes */
#include <stdio.h>
/* platform-specific includes */
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
int main() {
int wait = 5;
printf("hello!\n");
#ifdef _WIN32
Sleep(wait*1000);
#else
sleep(wait);
#endif
printf("goodbye!\n");
return 0;
}
khermans@khermans-laptop:~/projects$ gcc -std=c99 -Wall -o hello hello.c
khermans@khermans-laptop:~/projects$ time ./hello
hello!
goodbye!
real 0m5.005s
user 0m0.000s
sys 0m0.004s
khermans@khermans-laptop:~/projects$ i586-mingw32msvc-gcc -std=c99 -Wall -o hello.exe hello.c
khermans@khermans-laptop:~/projects$ file hello.exe
hello.exe: MS-DOS executable PE for MS Windows (console) Intel 80386 32-bit
khermans@khermans-laptop:~/projects$ time wine hello.exe
hello!
goodbye!
real 0m5.295s
user 0m0.004s
sys 0m0.012s
khermans@khermans-laptop:~/projects$ ls -lsh
total 212K
12K -rwxr-xr-x 1 khermans khermans 9.1K 2007-04-08 12:54 hello
4.0K -rw-r--r-- 1 khermans khermans 418 2007-04-08 12:53 hello.c
196K -rwxr-xr-x 1 khermans khermans 194K 2007-04-08 12:54 hello.exe
So there you have it. There is no need to boot into Windows for testing. Simply utilize mingw and wine. Now, go forth and start hacking!!!
| Attachment | Size |
|---|---|
| hello.txt | 420 bytes |
______________________
Kristian Erik Hermansen is a Linux Journal Reader Advisory Panelist. Track Me.
Trending Topics
| You Need A Budget | Feb 10, 2012 |
| The Linux powered LAN Gaming House | Feb 08, 2012 |
| Creating a vDSO: the Colonel's Other Chicken | Feb 06, 2012 |
| Your CMS Is Not Your Web Site | Feb 01, 2012 |
| Casper, the Friendly (and Persistent) Ghost | Jan 31, 2012 |
| Razor-qt 0.4 - Qt based Desktop Environment | Jan 30, 2012 |
- Fun with ethtool
- Parallel Programming with NVIDIA CUDA
- Readers' Choice Awards 2011
- 100% disappointed with the decision to go all digital.
- Linux-Based X Terminals with XDMCP
- Validate an E-Mail Address with PHP, the Right Way
- You Need A Budget
- The Linux powered LAN Gaming House
- Why Python?
- Python for Android
- Employment Posters
5 hours 27 min ago - Sure the best distro is
6 hours 48 min ago - BeOS was the best
9 hours 31 min ago - I use Wireshark on a daily
14 hours 2 min ago - buena información
19 hours 9 min ago - One important "bucket" that I didn't note (désolé si qqun deja d
20 hours 9 min ago - Gnome3 is such a POS. No one
1 day 5 hours ago - Gnome 3 is the biggest POS
1 day 5 hours ago - I didn't knew this thing by
1 day 11 hours ago - Author's reply
1 day 15 hours ago





Comments
Handy Dandy
Very nice! Thanks for the tip.
Adam Dutko is a Linux Journal Reader Advisory Panelist.
"...thanks for all the fish..."
http://littlehat.homelinux.org