Cross Compile Linux to Windows
Another option for building Windows executables with Eclipse on Linux is to use a cross compiler. To use this option, CDT must have the cross compile extension enabled, and a cross compiler must be installed. Under Ubuntu 10.10, installing the mingw32 package will bring in everything required to build the sample project with the MinGW cross compiler. Next, we'll install CDT cross compile support.
To install CDT cross compile support, navigate to Help → Install New Software... In the Work With textbox, type
cdt to filter down to CDT settings and select the CDT option. Expand CDT Optional Features and check the C/C++ Cross Compiler Support option. Hit Next and follow the instructions to complete the installation (Figure 8).
Installing the CDT cross compiler support provides new build configuration options. To see the new options, follow the previous instructions for creating a new build configuration. Under the Import Predefined dropdown box, two new options are available: Executable→Cross GCC→Debug, and Executable→Cross GCC→Release. Create a new build configuration called Debug-Win and select the Cross GCC→Debug option.
When this configuration is selected, you'll notice a new option in the project settings called Cross Settings. Open the project settings, select Cross Settings, and enter
i586-mingw32msvc- into the prefix textbox. If the prefix box is left empty, the IDE will use the default system tools for linking and compiling (Figure 9).
A Few Good Options
Eclipse offers a few options for creating cross-platform projects. It takes a bit of futzing, but developing between Linux and Windows works seamlessly once the project is setup. And there are other options that we didn't cover such as using GCC on Linux and Windows or creating makefiles by hand. Each option has its own set of quirks for dealing with
include directories, maintainability, third-party libraries, and debugging.
In this article, we covered handling
include directories and the options covered are arguably the easiest to maintain (since Eclipse automatically handles the makefile). If you want to debug on both platforms or use third-party libraries, there's a bit more work to do depending on the option chosen for cross-platform development. But we'll leave that for another time.
Ben DuPont is a software engineer. After 10 years of developing software and systems in a corporate environment, he founded Nebland Software, an independent software consulting company.