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.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Peppermint 7 Released
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Sony Settles in Linux Battle
- Libarchive Security Flaw Discovered
- Maru OS Brings Debian to Your Phone
- Snappy Moves to New Platforms
- Profiles and RC Files
- Understanding Ceph and Its Place in the Market
- Git 2.9 Released
- The Giant Zero, Part 0.x
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide