Developing for Windows on Linux
Replace the command mingw-gcc with whatever the package maintainer called the compiler executable for your package. Presto, you now have a Windows program ready for the world. Or is it?
Wine is the other great boon for developers who need to write programs for the Windows platform. The massive amount of work that has gone into Wine by its developers is phenomenal. This great program allows you to run Windows programs from within Linux. The upshot to this is we now can run our freshly compiled program and see if it actually works as advertised. To do this, use the command wine example1.exe, and you should see the window appear on your desktop (Figure 1). When you set up Wine, you have the options of windows being managed by your window manager, not managed or displayed on their own desktop. This affects how the window looks when you run it. What you see in Figure 1 is an unmanaged application.
If you weren't lucky enough to have typed your program perfectly, you may need to do some debugging to figure out what has gone wrong. Wine can be a great asset here. The option --debugmsg [debugchannel] outputs the results from one or more debug channels within Wine. Examples of the available debug channels are:
relay: writes a log message every time a Win32 function is called.
win: tracks Windows messages.
all: tracks all messages.
Don't use all unless you really need it. The amount of output quickly can overwhelm even the most detail-obsessed programmer. A complete list of available debug channels can be found on the Wine site.
We now have a wonderful, working, bug-free program that runs under Windows. Considering that all of the work was done under Linux, wouldn't it be nice if we also could have our program run under Linux? The good folks at the Wine Project have come to the rescue again. Part of the project includes winelib, a library that provides the interface to Linux for your Windows source code. In order to use this functionality, you need to install the wine-devel package for your distribution. If you installed from source, the required files already should be available.
Included in the wine-devel package is a Perl script called winemaker. This script is designed to go through your source files and directories and make the required changes to get it to compile correctly against winelib on Linux. Things it checks include filename case and line ending characters. In addition, it replaces file path back slashes with forward slashes and does many other things. By default, it backs up any source files it needs to change. It converts your project to winelib, making all kinds of automagic changes. To compile, you simply run:
winemaker . ./configure --with-wine=/path/to/wine make
to create a Linux executable. The dot you see above is there on purpose. You hand in the path where winemaker can find the source files it needs to analyze; here, the files are in the current directory.
In our case, our sample doesn't have any project files, and winemaker thinks this is a bit of a problem. We can do the steps involved simply by hand. Instead of executing mingw-gcc to compile our program, we use winegcc with the exact same command-line parameters. This creates a file ending in .so and a shell script to handle the program execution. We now have our Windows source code compiled and running under Linux.
I hope I've been able to convince some of the Windows developers out there that they can work effectively from within Linux. With GCC allowing compilation of an executable for Windows, and Wine providing great support in running and debugging, there is no real reason to boot up Windows in most cases. The only reason would be if your favourite IDE didn't run correctly under Wine, but then you always could volunteer to fix that problem, right?
As this was only a short introduction, I did not cover support for MFC or the creation of DLLs. Both of these topics are discussed in more detail at WineHQ and the MinGW site.
Resources for this article: /article/7555.
Joey Bernard is a systems architect for CARIS, a GIS company in Canada. He's never actually done any GIS work, mostly just Oracle, UNIX systems programming and some Windows programming.
Joey Bernard has a background in both physics and computer science. This serves him well in his day job as a computational research consultant at the University of New Brunswick. He also teaches computational physics and parallel programming.
|Free Today: September Issue of Linux Journal (Retail value: $5.99)||Sep 27, 2016|
|nginx||Sep 27, 2016|
|Epiq Solutions' Sidekiq M.2||Sep 26, 2016|
|Nativ Disc||Sep 23, 2016|
|Android Browser Security--What You Haven't Been Told||Sep 22, 2016|
|The Many Paths to a Solution||Sep 21, 2016|
- Free Today: September Issue of Linux Journal (Retail value: $5.99)
- Android Browser Security--What You Haven't Been Told
- Readers' Choice Awards 2013
- Epiq Solutions' Sidekiq M.2
- The Many Paths to a Solution
- Nativ Disc
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Synopsys' Coverity
- Tech Tip: Really Simple HTTP Server with Python
Pick up any e-commerce web or mobile app today, and you’ll be holding a mashup of interconnected applications and services from a variety of different providers. For instance, when you connect to Amazon’s e-commerce app, cookies, tags and pixels that are monitored by solutions like Exact Target, BazaarVoice, Bing, Shopzilla, Liveramp and Google Tag Manager track every action you take. You’re presented with special offers and coupons based on your viewing and buying patterns. If you find something you want for your birthday, a third party manages your wish list, which you can share through multiple social- media outlets or email to a friend. When you select something to buy, you find yourself presented with similar items as kind suggestions. And when you finally check out, you’re offered the ability to pay with promo codes, gifts cards, PayPal or a variety of credit cards.Get the Guide